[
  (string)
  (raw_string)
  (heredoc_body)
  (heredoc_start)
  (heredoc_end)
  (ansi_c_string)
  (word)
] @string

(variable_name) @variable

[
  "export"
  "function"
  "unset"
  "local"
  "declare"
] @keyword

[
  "case"
  "do"
  "done"
  "elif"
  "else"
  "esac"
  "fi"
  "for"
  "if"
  "in"
  "select"
  "then"
  "until"
  "while"
] @keyword.control

(comment) @comment

; Shebang
((program
  .
  (comment) @keyword.directive)
  (#match? @keyword.directive "^#![ \t]*/"))

(function_definition
  name: (word) @function)

(command_name
  (word) @function)

[
  (file_descriptor)
  (number)
] @number

(regex) @string.regex

[
  (command_substitution)
  (process_substitution)
  (expansion)
] @embedded

[
  "$"
  "&&"
  "||"
  ">"
  "<<"
  ">>"
  ">&"
  ">&-"
  "<"
  "|"
  ":"
  "//"
  "/"
  "%"
  "%%"
  "#"
  "##"
  "+="
  "-="
  "*="
  "/="
  "%="
  "**="
  "<<="
  ">>="
  "&="
  "^="
  "|="
  "="
  "=~"
  "=="
  "!="
  "-o"
  "-a"
  "^"
  "&"
  "<="
  ">="
  "+"
  "-"
  "*"
  "**"
  "!"
  "++"
  "--"
  "~"
  "?"
] @operator

(test_operator) @keyword.operator

";" @punctuation.delimiter

[
  "("
  ")"
  "{"
  "}"
  "["
  "]"
] @punctuation.bracket

(test_command
  [
    "[["
    "]]"
  ] @punctuation.bracket)

(compound_statement
  [
    "(("
    "))"
  ] @punctuation.bracket)

(simple_expansion
  "$" @punctuation.special)

(expansion
  "${" @punctuation.special
  "}" @punctuation.special) @embedded

(command_substitution
  "$(" @punctuation.special
  ")" @punctuation.special)

(arithmetic_expansion
  [
    "$(("
    "$["
    "))"
    "]"
  ] @punctuation.special)

((command
  (_) @constant)
  (#match? @constant "^-"))

(case_item
  value: (_) @string.regex)

(special_variable_name) @variable.special
