By default Sublime Text colors Bash keywords like echo
, for
, time
, and some more. However, I like how gEdit also colors cp
, mv
, and some others that Sublime Text doesn't highlight. How can I make Sublime Text recognize cp
and mv
(and maybe others) as keyboards and highlight them, for Bash script files (.sh)?
This happens when Sublime Text doesn't know which syntax highlighting to choose. First of all Sublime Text guesses the syntax from the file extension. E.g. if you have a file named my_file_name. php Sublime Text assumes that the PHP syntax highlighting is the best.
Save it as bash. sublime-build in the suggested directory, which should be anywhere in Sublime's Packages directory. Now if you open up a shell script, you can execute it through Sublime Text and have the output pop up in Sublime Text's console by running "Build With: bash" in the Command Palette.
To open a command palette in Sublime Text editor, you can use the shortcut key combination Ctrl+Shift+P on Windows and Cmd+Shift+P on OSX.
1st: Install the Package Control
Menu Tools -> the very bottom click on Install Package Control and wait a few seconds, it will tell you once successfully installed:
Package Control was successfully installed
(Restart sublime-text
for that menu item to disappear.)
2nd: View the Command Palette
Menu Tools -> at the very top click on Command Palette.
3rd: Search for Package Control: Install Package
Just type into the search box:
Package Control: Install Package
And click on it.
4th: Install the PackageResourceViewer plugin
Just type into the search box:
PackageResourceViewer
And click on it.
It will notify to about successful installation very shortly in the very bottom status bar.
5th: Open the resource viewer
View the Command Palette again.
Just type into the search box:
PackageResourceViewer: Open Resource
And click on it.
6th: Open ShellScript resource
Just type into the search box:
ShellScript
And click on it.
7th: Open Bash sublime-syntax configuration file
Just type into the search box:
Bash.sublime-syntax
And click on it.
It will open a file.
8th: Search for support.function.builtin.shell
Search via CTRL+F for this code:
support.function.builtin.shell
9th: Edit the match
line content to your liking
Out of the box this contains in the build 3126:
'(?<![-/])\b(?:alias|bg|bind|break|builtin|caller|cd|command|compgen|complete|dirs|disown|echo|enable|eval|exec|exit|false|fc|fg|getopts|hash|help|history|jobs|kill|let|logout|popd|printf|pushd|pwd|read|readonly|set|shift|shopt|source|suspend|test|times|trap|true|type|ulimit|umask|unalias|unset|wait)\b'
In later versions, I have tested build 3176, the file is structured heavily and there is no longer a single line to edit.
You will literally have to dig through the file and edit it to your liking.
10th: Save the file and continue working
CTRL+S
You don't need to restart sublime-text
in order for the new settings to apply.
Command Palette -> PackageResourceViewer: Open Resource
-> ShellScript
-> Shell-Unix-Generic.tmLanguage
Scroll down to ~ line 1750 and add/edit support.function.builtin.shell
<dict>
<key>match</key>
<string>(?<![-/])\b(?:alias|bg|bind|break|builtin|caller|cd|command|....)\b</string>
<key>name</key>
<string>support.function.builtin.shell</string>
</dict>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With