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

rowbearto

  • Senior Community Member
  • Posts: 2335
  • Hero Points: 132
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: 6862
  • Hero Points: 528
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: 2335
  • Hero Points: 132
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: 6862
  • Hero Points: 528
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: 2335
  • Hero Points: 132
Re: Determine language from hashbang !# at top of extension-less files
« Reply #4 on: September 25, 2017, 01:09:56 PM »
Works great! Thanks!