Author Topic: Determine language from hashbang !# at top of extension-less files  (Read 147 times)

rowbearto

  • Senior Community Member
  • Posts: 759
  • Hero Points: 24
I have many scripts that don't have extensions, such as python scripts or bash scripts. They start with a line as follows:

#!/usr/bin/env bash
#!/bin/bash
#!/usr/bin/env python
#!/bin/python
#!/bin/ksh

As these files don't have an extension, SE doesn't know they are a bash, python or ksh script.

It would be good if SE could look for the #! line at the top of extension-less scripts to help figure out what type of file it is, so that it can get the color coding right.

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 3951
  • Hero Points: 256
Re: Determine language from hashbang !# at top of extension-less files
« Reply #1 on: September 22, 2017, 02:05:28 am »
SlickEdit supports recognizing all of the examples you gave.

What I did noticed is that if you create the file in SlickEdit, save it, close it, and the reopen the file. You get plain text mode because SlickEdit save/restores (perfile.xml and vrestore.slk) the mode it was the last time you edited it. Just select the mode, if you create the file in SlickEdit.

rowbearto

  • Senior Community Member
  • Posts: 759
  • Hero Points: 24
Re: Determine language from hashbang !# at top of extension-less files
« Reply #2 on: September 22, 2017, 11:43:18 am »
OK - that must be the reason, as I create most of my scripts in SE.

How about creating a command to re-determine the type from the hashbang so that I don't have to go through all the clicks to re-classify the file? I can just run this new command instead (and bind it to a key).
« Last Edit: September 22, 2017, 02:18:34 pm by rowbearto »

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 3951
  • Hero Points: 256
Re: Determine language from hashbang !# at top of extension-less files
« Reply #3 on: September 25, 2017, 12:32:58 am »
Try this macro.

rowbearto

  • Senior Community Member
  • Posts: 759
  • Hero Points: 24
Re: Determine language from hashbang !# at top of extension-less files
« Reply #4 on: September 25, 2017, 01:09:56 pm »
Works great! Thanks!