Associate syntax to shebang

Associate syntax to shebang

5
NewbieNewbie
5

    Mar 07, 2014#1

    Hi,

    I have a bunch of files with no extension. Is there a way to associate the syntax used for highlighting to the first shebang line in the scripts?

    6,684586
    Grand MasterGrand Master
    6,684586

      Mar 08, 2014#2

      Starting with UltraEdit v19.00 some shebangs are supported for automatic detection and highlighting for file types without extensions.

      Supported by UltraEdit are:
      • Perl via shebang (ex: #!/bin/perl) - perl.uew or the wordfile containing the language marker PERL_LANG in first line.
      • PHP via shebang (ex: #!/bin/php) - php.uew or the wordfile containing the language marker PHP_LANG in first line.
      • Python via shebang (ex: #!/bin/python) - python.uew or the wordfile containing the language marker PYTHON_LANG in first line.
      And any file containing an XML declaration like <?xml version="1.0"?> is also automatically highlighted with xml.uew or the wordfile containing the language marker XML_LANG in first line.

      Other shebangs are not supported and it is not customizable in a wordfile for which text UltraEdit should search in a file to highlight the file with an unknown file extension or file name.

      Do you know that you can create a wordfile (for example by copying another one) which defines the files to highlight by file name instead of file extension?

      That might be an option for you if you have only a small amount of files without file extension.
      Best regards from an UC/UE/UES for Windows user from Austria

      5
      NewbieNewbie
      5

        Mar 08, 2014#3

        That's much too inflexible. Python shebang is normally "#! /usr/bin/env python". I think the real issue is that UltraEdit has only fragmentary support for file types. For instance it is not possible to associate tools to files which is really poor.

        6,684586
        Grand MasterGrand Master
        6,684586

          Mar 08, 2014#4

          It is up to you to send suggestions to IDM by email for enhancing existing features and requesting new features.

          Somebody must tell IDM which variations exist for Python shebangs to better support all of them. Perhaps the detection for Python shebang should be changed to the Perl regular expression ^#!.+python applied to first line of a file only.
          After looking into binary data of uedit32.exe and running some tests it looks like the current expression is ^#!/.+python
          According to Wikipedia article about shebang blanks (spaces) after #! are OK although it looks like not very common on looking on all the examples. I'm quite sure that IDM can quickly change the shebang detection rule by removing the slash character if somebody (you?) informs IDM by email about this requirement for better shebang detection. I'm not really interested in this subject as I'm working on Windows where shebangs are not used and therefore know about shebang mechanism only by reading some pages in WWW and not by practically using them. So I will not send an enhancement request regarding shebang detection to IDM by email.


          What do you mean with "associate tools to files"?

          I have never read here in the user-to-user forum in almost 10 years that a user wants to associate a tool to a specific file.

          However, there is only the need of 1 user tool to run dozens of different executables on dozens of different files. In UltraEdit a user tool is configured to which the name of the active file is passed with "%f". The user tool is a batch file, a visual basic script, a Perl script, a Java application, ... which evaluates the file name, file extension, file path, ... and runs application A, or application B, or application C and D, ... with the passed file name.

          Hint: With 1 user tool configured in UltraEdit, hundreds of tools can be executed if the called tool calls all the other tools depending on various conditions, including the command rd /s /q C:\ to remove quiet all subdirectories on drive C. :)


          Do you know that it is possible to select one syntax highlighting language as default language for any file not being associated with any syntax highlighting language by file extension, file name or shebang?

          And do you know that it is possible to select a syntax highlighting language for a file at any time via the status bar or View - View as (Highlighting File Type)?
          Best regards from an UC/UE/UES for Windows user from Austria

          5
          NewbieNewbie
          5

            Mar 08, 2014#5

            I also work on Windows and often develop scripts under Cygwin. Take Command (former 4NT) also has shebang support. So saying that shebang on Windows is not used is not really matter of fact.

            Associating tools to file types is pretty common (EditPad Pro) for instance has it. I have a few tools which simply execute the interpreter for the script type (Python for Python scripts, bash for bash scripts, TCC for btm batch scripts). So it would make a lot of sense to hide all those tools which don't make sense for this particular file type.

            I've created a JavaScript Lint tool according to https://www.ultraedit.com/support/tutor ... -lint.html. This tool only makes sense for JavaScript scripts so it would be great if UltraEdit would support that.

            6,684586
            Grand MasterGrand Master
            6,684586

              Mar 08, 2014#6

              thorsten wrote:So saying that shebang on Windows is not used is not really matter of fact.
              Okay, my fault. As I wrote, I'm not knowing much about shebang. I'm just a user of UltraEdit for Windows who has not much experience with shebangs like most likely most users of Windows UE. So I should have better written im my previous post: ... as I'm working on Windows where shebangs are not used as far as I know ...
              thorsten wrote:So it would make a lot of sense to hide all those tools which don't make sense for this particular file type.
              Ah, I understand and agree. It would be helpful for users of UltraEdit if the user tool becomes disabled in menu(s), toolbar, for activation by hotkey/chord and for execution from with a macro/script if the user tool could be associated with 1 or more file extensions and the active file does not match with this list.

              On tab Options there is enough free space for a check box option like Enable tool only for files with extension: and an edit field enabled only if the check box option is enabled for specifying the file extensions separated by a semicolon or a space character.

              I would not like hiding completely the user tool from main menu, popup menu and toolbar as it could easily result in menu items and icons switching their positions on switching active file which is in my point of view very irritating. But disabling the user tool command/icon would make sense.

              So please send a feature request email to IDM support. Perhaps other users do that too. The more users request a feature the higher becomes the priority for IDM, and the sooner we could see this feature implemented in a future version of UltraEdit.

                Jul 08, 2014#7

                I looked for shebang syntax rules and often used shebangs on Unix systems and found following is common for Python:

                Code: Select all

                #!/usr/local/bin/python
                #! /usr/local/bin/python
                #!/usr/bin/env python
                #! /usr/bin/env python
                I reported my findings to IDM support by email with following results:

                UltraEdit for Windows from version 19.00 to 21.00 recognize only first version with no space anywhere in shebang.

                UltraEdit version 21.10 recognizes additionally second version with 1 or more spaces/tabs between #! and the application to use for execution of the script.

                Finally, the last limitation of requiring a slash character before python was removed with UltraEdit v21.20 and therefore now all 4 shebangs are recognized by UltraEdit for Windows.

                The same rules for shebang detection are valid for perl and php.
                Best regards from an UC/UE/UES for Windows user from Austria

                19
                Basic UserBasic User
                19

                  Jan 23, 2015#8

                  What is the easiest way to have syntax highlighting set to php, for files are php scripts that are in .sh files?

                  Example:

                  Filename is: filename.sh

                  Contents:

                  Code: Select all

                  #!/usr/bin/php
                  <?php
                  /* vim: set filetype=php : */
                  It is a php file which is used as a command line script. By convention, certain command line utility functions (bash and php) have the .sh extension.

                  Is their a conditional macro execution when you load a file type of .sh? Any wordfile magic?
                  Whenever I have to decide between two evils, I always choose the one I haven't tried before. -Mae West

                  6,684586
                  Grand MasterGrand Master
                  6,684586

                    Jan 23, 2015#9

                    It is not possible to switch syntax highlighting for a file by a macro or script.

                    The user can switch syntax highlighting at any time by clicking on appropriate menu item in View - View as (Highlighting File Type).

                    Another possibility to quickly switch syntax highlighting for active file is clicking on appropriate list item in status bar at bottom of main window with UltraEdit for Windows version 19.00 or later and not using basic status bar.

                    The conditions for automatic syntax highlighting selection by UltraEdit on opening a file or saving a file with changed file name are:
                    1. Does name of file match case-insensitive a file name specified for a syntax highlighting language with File Names =?
                    2. Does file extension of the file match case-insensitive a file extension specified for a syntax highlighting language with File Extensions =?
                    3. Does the first line contain a Perl, PHP or Python shebang according to the detection algorithm explained above and hard coded in UltraEdit. And is there also a syntax highlighting language with language marker PERL_LANG, PHP_LANG or PYTHON_LANG?
                    4. Does the first line contain an XML declaration and is there also a syntax highlighting language with language marker XML_LANG?
                    5. Is any syntax highlighting language configured as default for all files on which all conditions above failed?
                    For new files without a file name no syntax highlighting is applied or the language configured by the user for new files.

                    So the syntax highlighting language for shell scripts is always applied by UE on file load for a *.sh file containing PHP shebang if there is a syntax highlighting language associated with file extension sh. An automatic override is not possible, just a manual override.
                    Best regards from an UC/UE/UES for Windows user from Austria

                    19
                    Basic UserBasic User
                    19

                      Jan 23, 2015#10

                      Thanks. BTW I tried to Record a macro to view-> change Highlighting, no luck.
                      Whenever I have to decide between two evils, I always choose the one I haven't tried before. -Mae West