ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

Shell​Script​Improved

by jfcherng ST3

A better ShellScript (Bash) syntax highlight for Sublime Text >= 3116

Details

Installs

  • Total 4K
  • Win 1K
  • OS X 1K
  • Linux 2K
Sep 19 Sep 18 Sep 17 Sep 16 Sep 15 Sep 14 Sep 13 Sep 12 Sep 11 Sep 10 Sep 9 Sep 8 Sep 7 Sep 6 Sep 5 Sep 4 Sep 3 Sep 2 Sep 1 Aug 31 Aug 30 Aug 29 Aug 28 Aug 27 Aug 26 Aug 25 Aug 24 Aug 23 Aug 22 Aug 21 Aug 20 Aug 19 Aug 18 Aug 17 Aug 16 Aug 15 Aug 14 Aug 13 Aug 12 Aug 11 Aug 10 Aug 9 Aug 8 Aug 7 Aug 6 Aug 5
Windows 4 7 2 3 9 9 6 3 0 2 2 0 3 3 1 2 2 1 2 3 4 1 3 3 2 2 2 7 3 2 1 2 5 5 6 2 6 0 0 4 3 2 3 4 0 2
OS X 5 14 3 3 5 8 5 1 2 1 0 1 5 2 6 3 2 0 6 2 4 0 3 5 4 4 4 2 2 5 1 6 5 3 3 5 3 1 1 3 4 5 3 4 2 2
Linux 6 3 1 4 6 15 4 8 3 5 6 3 6 6 3 4 2 2 4 6 0 0 6 1 3 7 2 3 2 3 3 6 3 2 7 4 1 1 3 7 5 4 3 4 1 3

Readme

Source
raw.​githubusercontent.​com

Sublime-ShellScriptImproved

A better ShellScript (Bash) syntax highlight for Sublime Text >= 3116.

Note that here is an official ShellScript syntax rewrite issue. If the rewritten one comes out and is good enough for, at least, Bash, I may drop support for this repository.

Pros

  • It fixes quite lots of bugs which exist in the official ShellScript (Bash) syntax.
  • It parses things more grammatically while the official one is just like a keyword highlighter.

Cons

  • It is designed for Bash only while the official one is designed for general shell scripts.
  • You may have to add customized scopes to your color scheme if you do not want to use the bundled one.
  • Its source code is as messy as the official one's but this does not matter if you are not a maintainer.

Screenshots

Left / Right = Official ShellScript (Bash) / ShellScript Improved screenshot

Color scheme

There are quite a lot of scopes that may be missing in the color scheme you are using. If you want to add them by yourself, see the Customization from Your Color Scheme section. Or, you can set the syntax specific settings to use the color scheme which is shipped with this package.

To do that,

  1. Open a file with ShellScript Improved syntax.
  2. Go to Preferences » Settings - More » Syntax Specific - User
  3. Add the color_scheme item into the settings file and then save.
{
    // use a bundled color scheme while writing shell scripts
    "color_scheme": "Packages/ShellScriptImproved/color_schemes/dark.tmTheme"
}

That color scheme is the exact one I use in my Sublime Text so there is only a dark one. You would get the same highlighting as shown in the screenshot.

Customization from Your Color Scheme

Note that an extra rule is added to my .tmTheme in above screenshots in order to set text to its default color, i.e., white on dark theme and black on light theme mostly. (I just can not find other way to set text to the default text color…) This resets the color of TEXT in $(echo TEXT) and other things like that.

<dict>

    <key>name</key>
    <string>Embedded</string>
    <key>scope</key>
    <string>meta.embedded</string>
    <key>settings</key>
    <dict>
        <key>foreground</key>
        <string>#FFFFFF</string>
    </dict>
</dict>
<dict>

    <key>name</key>
    <string>Reset Color</string>
    <key>scope</key>
    <string>meta.reset.color</string>
    <key>settings</key>
    <dict>
        <key>foreground</key>
        <string>#FFFFFF</string>
    </dict>
</dict>

Also, those scopes may be missing in your theme. You may add/adjust them to get a better color highlighting.

<dict>
    <key>name</key>
    <string>Shell - variable</string>
    <key>scope</key>
    <string>variable.other.normal.shell, variable.other.positional.shell, variable.other.bracket.shell, variable.other.special.shell, variable.other.loop.shell, variable.other.c-style.shell,variable.other.positional.shell</string>
    <key>settings</key>
    <dict>
        <key>fontStyle</key>
        <string>bold</string>
        <key>foreground</key>
        <string>#AE81FF</string>
    </dict>
</dict>
<dict>
    <key>name</key>
    <string>Shell - bracket variable in meta.reset.color</string>
    <key>scope</key>
    <string>meta.reset.color variable.other.bracket.shell, meta.reset.color variable.other.bracket.shell variable.other.bracket.shell, meta.reset.color variable.other.bracket.shell variable.other.bracket.shell variable.other.bracket.shell</string>
    <key>settings</key>
    <dict>
        <key>fontStyle</key>
        <string>bold</string>
        <key>foreground</key>
        <string>#AE81FF</string>
    </dict>
</dict>
<dict>
    <key>name</key>
    <string>Shell - true</string>
    <key>scope</key>
    <string>variable.other.true.shell</string>
    <key>settings</key>
    <dict>
        <key>foreground</key>
        <string>#AAFFFF</string>
    </dict>
</dict>
<dict>
    <key>name</key>
    <string>Shell - false</string>
    <key>scope</key>
    <string>variable.other.false.shell</string>
    <key>settings</key>
    <dict>
        <key>foreground</key>
        <string>#FFAAFF</string>
    </dict>
</dict>
<dict>
    <key>name</key>
    <string>Shell - built-in command</string>
    <key>scope</key>
    <string>support.function.builtin.shell</string>
    <key>settings</key>
    <dict>
        <key>fontStyle</key>
        <string>bold</string>
        <key>foreground</key>
        <string>#50AAFF</string>
    </dict>
</dict>
<dict>
    <key>name</key>
    <string>Shell - privilege command</string>
    <key>scope</key>
    <string>support.function.privilege.shell</string>
    <key>settings</key>
    <dict>
        <key>fontStyle</key>
        <string>bold</string>
        <key>foreground</key>
        <string>#FF0000</string>
    </dict>
</dict>
<dict>
    <key>name</key>
    <string>Shell - external command</string>
    <key>scope</key>
    <string>support.function.external.shell</string>
    <key>settings</key>
    <dict>
        <key>fontStyle</key>
        <string>bold</string>
        <key>foreground</key>
        <string>#0684F4</string>
    </dict>
</dict>
<dict>
    <key>name</key>
    <string>Shell - punctuation variable</string>
    <key>scope</key>
    <string>punctuation.definition.variable.shell</string>
    <key>settings</key>
    <dict>
        <key>fontStyle</key>
        <string>bold</string>
        <key>foreground</key>
        <string>#AE81FF</string>
    </dict>
</dict>
<dict>
    <key>name</key>
    <string>Shell - punctuation definition</string>
    <key>scope</key>
    <string>punctuation.definition.string</string>
    <key>settings</key>
    <dict>
        <key>fontStyle</key>
        <string>bold</string>
        <key>foreground</key>
        <string>#E6DB74</string>
    </dict>
</dict>
<dict>
    <key>name</key>
    <string>Shell - pipe-sign/parentheses in "case"</string>
    <key>scope</key>
    <string>punctuation.separator.pipe-sign.shell, punctuation.definition.case-pattern.shell</string>
    <key>settings</key>
    <dict>
        <key>fontStyle</key>
        <string>bold</string>
        <key>foreground</key>
        <string>#F92672</string>
    </dict>
</dict>
<dict>
    <key>name</key>
    <string>Shell - ";;" in "case"</string>
    <key>scope</key>
    <string>punctuation.terminator.case-clause.shell</string>
    <key>settings</key>
    <dict>
        <key>fontStyle</key>
        <string>bold</string>
        <key>foreground</key>
        <string>#F92672</string>
    </dict>
</dict>
<dict>
    <key>name</key>
    <string>Shell - command switch</string>
    <key>scope</key>
    <string>support.command-switch.shell</string>
    <key>settings</key>
    <dict>
        <key>fontStyle</key>
        <string>bold italic</string>
    </dict>
</dict>

See Also

License

The MIT License (MIT)

Copyright © 2017 Jack Cherng

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Supporters

Thank you guys for sending me some cups of coffee.