2020-04-20 20:15:43 +03:00
## Syntax highlighting for Bourne shell scripts.
2014-05-17 00:21:34 +04:00
2019-12-16 21:09:48 +03:00
syntax sh "(\.sh|(\.|/)(a|ba|c|da|k|mk|pdk|tc|z)sh(rc|_profile)?|/(etc/|\.)profile)$"
2021-04-27 12:18:41 +03:00
header "^#!.*/((env[[:blank:]]+)?((a|ba|c|da|k|mk|pdk|tc|z)?sh)|busybox[[:blank:]]+sh|openrc-run|runscript)\>"
2020-09-27 20:35:27 +03:00
header "-\*-.*shell-script.*-\*-"
2017-11-19 13:10:53 +03:00
magic "(POSIX|Bourne-Again) shell script.*text"
2016-05-25 23:13:50 +03:00
comment "#"
2014-05-17 00:21:34 +04:00
2019-11-04 21:52:35 +03:00
linter dash -n
2018-03-28 15:30:07 +03:00
# Function declarations.
color brightgreen "^[A-Za-z0-9_-]+\(\)"
# Keywords, symbols, and comparisons.
2014-02-27 01:33:47 +04:00
color green "\<(break|case|continue|do|done|elif|else|esac|exit|fi|for|function|if|in|read|return|select|shift|then|time|until|while)\>"
color green "\<(declare|eval|exec|export|let|local)\>"
2021-10-18 13:04:31 +03:00
color green "[][{}():;|`$<>!=&\]"
2018-03-28 15:30:07 +03:00
color green "-(eq|ne|gt|lt|ge|le|ef|ot|nt)\>"
# Short and long options.
2018-03-30 11:45:04 +03:00
color brightmagenta "[[:blank:]]-[A-Za-z]\>" "[[:blank:]]--[A-Za-z-]+\>"
2018-03-28 15:30:07 +03:00
# Common commands.
2018-03-27 15:07:58 +03:00
color brightblue "\<(awk|cat|cd|ch(grp|mod|own)|cp|cut|echo|env|grep|head|install|ln|make|mkdir|mv|popd|printf|pushd|rm|rmdir|sed|set|sort|tail|tar|touch|umask|unset)\>"
2018-03-27 20:41:00 +03:00
color normal "[.-]tar\>"
2014-05-17 00:21:34 +04:00
2014-02-27 01:33:47 +04:00
# Basic variable names (no braces).
color brightred "\$[-0-9@*#?$!]" "\$[[:alpha:]_][[:alnum:]_]*"
# More complicated variable names; handles braces and replacements and arrays.
2021-04-27 12:18:41 +03:00
color brightred "\$\{[#!]?([-@*#?$!]|[0-9]+|[[:alpha:]_][[:alnum:]_]*)(\[([[:blank:]]*[[:alnum:]_]+[[:blank:]]*|@)\])?(([#%/]|:?[-=?+])[^}]*\}|\[|\})"
2014-05-17 00:21:34 +04:00
# Comments.
2021-04-27 12:18:41 +03:00
color cyan "(^|[[:blank:]])#.*"
2014-05-17 00:21:34 +04:00
# Strings.
2021-10-26 15:08:35 +03:00
color brightyellow ""(\\.|[^"\])*"|'(\\.|[^'\])*'"
2014-05-17 00:21:34 +04:00
# Trailing whitespace.
2007-04-12 02:18:16 +04:00
color ,green "[[:space:]]+$"