Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make Sublime Text color common Bash commands (cp, mv, ...)

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)?

like image 601
becko Avatar asked Mar 25 '15 12:03

becko


People also ask

Why is my Sublime Text white?

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.

How do I run a bash script in sublime?

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.

How do I run a command in Sublime Text?

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.


2 Answers

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.

like image 60
LinuxSecurityFreak Avatar answered Sep 29 '22 02:09

LinuxSecurityFreak


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>(?&lt;![-/])\b(?:alias|bg|bind|break|builtin|caller|cd|command|....)\b</string>
  <key>name</key>
    <string>support.function.builtin.shell</string>
</dict>
like image 43
AGS Avatar answered Sep 29 '22 02:09

AGS