2020-04-20 19:15:43 +02:00
## Syntax highlighting for Bourne shell scripts.
2014-05-16 20:21:34 +00:00
2019-12-16 19:09:48 +01:00
syntax sh "(\.sh|(\.|/)(a|ba|c|da|k|mk|pdk|tc|z)sh(rc|_profile)?|/(etc/|\.)profile)$"
2020-12-25 16:47:49 +01:00
header "^#!.*/((env\s+)?((a|ba|c|da|k|mk|pdk|tc|z)?sh)|busybox\s+sh|openrc-run|runscript)\>"
2020-09-27 19:35:27 +02:00
header "-\*-.*shell-script.*-\*-"
2017-11-19 11:10:53 +01:00
magic "(POSIX|Bourne-Again) shell script.*text"
2016-05-25 22:13:50 +02:00
comment "#"
2014-05-16 20:21:34 +00:00
2019-11-04 20:52:35 +02:00
linter dash -n
2018-03-28 14:30:07 +02:00
# Function declarations.
color brightgreen "^[A-Za-z0-9_-]+\(\)"
# Keywords, symbols, and comparisons.
2014-02-26 21:33:47 +00: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)\>"
color green "[{}():;|`$<>!=&\\]" "(\]|\[)"
2018-03-28 14:30:07 +02:00
color green "-(eq|ne|gt|lt|ge|le|ef|ot|nt)\>"
# Short and long options.
2018-03-30 10:45:04 +02:00
color brightmagenta "[[:blank:]]-[A-Za-z]\>" "[[:blank:]]--[A-Za-z-]+\>"
2018-03-28 14:30:07 +02:00
# Common commands.
2018-03-27 14:07:58 +02: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 19:41:00 +02:00
color normal "[.-]tar\>"
2014-05-16 20:21:34 +00:00
2014-02-26 21:33:47 +00:00
# Basic variable names (no braces).
color brightred "\$[-0-9@*#?$!]" "\$[[:alpha:]_][[:alnum:]_]*"
# More complicated variable names; handles braces and replacements and arrays.
color brightred "\$\{[#!]?([-@*#?$!]|[0-9]+|[[:alpha:]_][[:alnum:]_]*)(\[([[:space:]]*[[:alnum:]_]+[[:space:]]*|@)\])?(([#%/]|:?[-=?+])[^}]*\}|\[|\})"
2014-05-16 20:21:34 +00:00
# Comments.
2018-11-03 21:12:44 +01:00
color cyan "(^|[[:space:]])#.*"
2014-05-16 20:21:34 +00:00
# Strings.
2014-02-26 21:33:47 +00:00
color brightyellow ""(\\.|[^"])*"" "'(\\.|[^'])*'"
2014-05-16 20:21:34 +00:00
# Trailing whitespace.
2007-04-11 22:18:16 +00:00
color ,green "[[:space:]]+$"