{
  "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
  "firstLineMatch": "^#!.*\\bfish\\b",
  "keyEquivalent": "^~F",
  "name": "fish",
  "patterns": [
    { "include": "#string-double" },
    { "include": "#string-single" },
    { "include": "#comment" },
    { "include": "#subshell-bare" },
    { "include": "#subshell" },
    { "include": "#command" },
    { "include": "#keywords" },
    { "include": "#io-redirection" },
    { "include": "#operators" },
    { "include": "#options" },
    { "include": "#variable" },
    { "include": "#escape" }
  ],
  "repository": {
    "string-double": {
      "begin": "\"",
      "beginCaptures": {
        "0": { "name": "punctuation.definition.string.begin.fish" }
      },
      "comment": "Double quoted string",
      "end": "\"",
      "endCaptures": {
        "0": { "name": "punctuation.definition.string.end.fish" }
      },
      "name": "string.quoted.double.fish",
      "patterns": [
        { "include": "#subshell" },
        { "include": "#variable-string-double" },
        {
          "comment": "https://fishshell.com/docs/current/#quotes",
          "match": "\\\\(\\\"|\\$|$|\\\\)",
          "name": "constant.character.escape.fish"
        }
      ]
    },
    "string-single": {
      "begin": "'",
      "beginCaptures": {
        "0": { "name": "punctuation.definition.string.begin.fish" }
      },
      "comment": "Single quoted string",
      "end": "'",
      "endCaptures": {
        "0": { "name": "punctuation.definition.string.end.fish" }
      },
      "name": "string.quoted.single.fish",
      "patterns": [
        {
          "comment": "https://fishshell.com/docs/current/#quotes",
          "match": "\\\\('|`|\\\\)",
          "name": "constant.character.escape.fish"
        }
      ]
    },
    "comment": {
      "captures": { "1": { "name": "punctuation.definition.comment.fish" } },
      "comment": "line comment",
      "match": "(?<!\\$)(#)(?!\\{).*$\\n?",
      "name": "comment.line.number-sign.fish"
    },
    "command": {
      "comment": "name of command, either a function or a binary",
      "match": "(^\\s*|&&\\s*|(\\|)\\s*|\\(\\s*|[;]\\s*|\\b(if|while)\\b\\s+)(?!(?<!\\.)\\b(function|while|if|else|switch|case|for|in|begin|end|continue|break|return|source|exit|wait|and|or|not)\\b(?![?!]))([a-zA-Z_\\-0-9\\[\\].]+)",
      "captures": {
        "2": { "name": "keyword.operator.pipe.fish" },
        "3": { "name": "keyword.control.fish" },
        "5": { "name": "support.function.command.fish" }
      }
    },
    "command-subshell": {
      "comment": "name of command in subshell context",
      "match": "(\\G\\s*|&&\\s*|(\\|)\\s*|\\(\\s*|[;]\\s*|\\b(if|while)\\b\\s+)(?!(?<!\\.)\\b(function|while|if|else|switch|case|for|in|begin|end|continue|break|return|source|exit|wait|and|or|not)\\b(?![?!]))([a-zA-Z_\\-0-9\\[\\].]+)",
      "captures": {
        "2": { "name": "keyword.operator.pipe.fish" },
        "3": { "name": "keyword.control.fish" },
        "5": { "name": "support.function.command.fish" }
      }
    },
    "keywords": {
      "patterns": [
        {
          "comment": "command-expecting keywords (allow subsequent keywords)",
          "match": "(^\\s*|&&\\s*|(?<=\\|)\\s*|\\(\\s*|[;]\\s*|(?<=\\bwhile\\b)\\s+|(?<=\\bif\\b)\\s+|(?<=\\band\\b)\\s+|(?<=\\bor\\b)\\s+|(?<=\\bnot\\b)\\s+)(?<!\\.)\\b(while|if|and|or|not)\\b(?![?!])",
          "captures": { "2": { "name": "keyword.control.fish" } }
        },
        {
          "comment": "regular keywords (command position only)",
          "match": "(^\\s*|&&\\s*|(?<=\\|)\\s*|\\(\\s*|[;]\\s*)(?<!\\.)\\b(function|else|switch|case|for|begin|end|continue|break|return|source|exit|wait)\\b(?![?!])",
          "captures": { "2": { "name": "keyword.control.fish" } }
        },
        {
          "comment": "in keyword (special case for 'for' loops)",
          "match": "\\b(in)\\b(?![?!])",
          "name": "keyword.control.fish"
        }
      ]
    },
    "keywords-subshell": {
      "patterns": [
        {
          "comment": "command-expecting keywords in subshell (allow subsequent keywords)",
          "match": "(\\G\\s*|&&\\s*|(?<=\\|)\\s*|\\(\\s*|[;]\\s*|(?<=\\bwhile\\b)\\s+|(?<=\\bif\\b)\\s+|(?<=\\band\\b)\\s+|(?<=\\bor\\b)\\s+|(?<=\\bnot\\b)\\s+)(?<!\\.)\\b(while|if|and|or|not)\\b(?![?!])",
          "captures": { "2": { "name": "keyword.control.fish" } }
        },
        {
          "comment": "regular keywords in subshell (command position only)",
          "match": "(\\G\\s*|&&\\s*|(?<=\\|)\\s*|\\(\\s*|[;]\\s*)(?<!\\.)\\b(function|else|switch|case|for|begin|end|continue|break|return|source|exit|wait)\\b(?![?!])",
          "captures": { "2": { "name": "keyword.control.fish" } }
        },
        {
          "comment": "in keyword (special case for 'for' loops)",
          "match": "\\b(in)\\b(?![?!])",
          "name": "keyword.control.fish"
        }
      ]
    },
    "io-redirection": {
      "patterns": [
        {
          "comment": "IO Redirection with simple target",
          "match": "(<|(?:>|\\^|>>|\\^\\^)(?:&[012\\-])?|[012](?:<|>|>>)(?:&[012\\-])?)\\s*(?!\\()([a-zA-Z0-9_./\\-]+)",
          "captures": {
            "1": { "name": "keyword.operator.redirect.fish" },
            "2": { "name": "keyword.operator.redirect.target.fish" }
          }
        },
        {
          "comment": "IO Redirection without target",
          "match": "(?x:\n<|(>|\\^|>>|\\^\\^)(&[012\\-])?|[012](<|>|>>)(&[012\\-])?)",
          "name": "keyword.operator.redirect.fish"
        }
      ]
    },
    "operators": {
      "patterns": [
        {
          "match": "&",
          "name": "keyword.operator.background.fish"
        },
        {
          "match": "\\*\\*|\\*|\\?",
          "name": "keyword.operator.glob.fish"
        }
      ]
    },
    "options": {
      "comment": "command short/long options",
      "match": "\\s(-{1,2}[a-zA-Z_\\-0-9]+|-\\w)\\b",
      "captures": { "1": { "name": "source.option.fish" } }
    },
    "subshell": {
      "comment": "Command substitution $(command)",
      "begin": "\\$\\(",
      "beginCaptures": {
        "0": { "name": "punctuation.definition.subshell.begin.fish" }
      },
      "end": "(?<!\\\\)((\\\\\\\\)*)(\\))",
      "endCaptures": {
        "1": { "name": "constant.character.escape.string.fish" },
        "3": { "name": "punctuation.definition.subshell.end.fish" }
      },
      "name": "meta.embedded.subshell.fish",
      "patterns": [
        { "include": "#string-double" },
        { "include": "#string-single" },
        { "include": "#comment" },
        { "include": "#keywords-subshell" },
        { "include": "#command-subshell" },
        { "include": "#io-redirection" },
        { "include": "#operators" },
        { "include": "#options" },
        { "include": "#subshell" },
        { "include": "#variable" },
        { "include": "#escape" }
      ]
    },
    "slice": {
      "comment": "List variable slice $variable[...] outside of strings",
      "begin": "\\[",
      "beginCaptures": {
        "0": { "name": "punctuation.definition.slice.begin.fish" }
      },
      "end": "(?<!\\\\)((\\\\\\\\)*)(\\])",
      "endCaptures": {
        "1": { "name": "constant.character.escape.string.fish" },
        "3": { "name": "punctuation.definition.slice.end.fish" }
      },
      "name": "meta.embedded.slice.fish variable.interpolation.fish",
      "patterns": [
        { "include": "#string-double" },
        { "include": "#string-single" },
        { "include": "#subshell-bare" },
        { "include": "#subshell" },
        { "include": "#variable" },
        { "include": "#escape" }
      ]
    },
    "slice-string-double": {
      "comment": "List variable slice $variable[...] inside double-quoted strings",
      "begin": "\\[",
      "beginCaptures": {
        "0": { "name": "punctuation.definition.slice.begin.fish" }
      },
      "end": "(?<!\\\\)((\\\\\\\\)*)(\\])",
      "endCaptures": {
        "1": { "name": "constant.character.escape.string.fish" },
        "3": { "name": "punctuation.definition.slice.end.fish" }
      },
      "name": "meta.embedded.slice.fish variable.interpolation.string.fish",
      "patterns": [
        { "include": "#subshell" },
        { "include": "#variable" },
        {
          "comment": "https://fishshell.com/docs/current/#quotes",
          "match": "\\\\(\\\"|\\$|$|\\\\)",
          "name": "constant.character.escape.fish"
        }
      ]
    },
    "subshell-bare": {
      "comment": "Bare parentheses command substitution (command) - valid in fish 3.4+",
      "begin": "\\(",
      "beginCaptures": {
        "0": { "name": "punctuation.definition.subshell.begin.fish" }
      },
      "end": "(?<!\\\\)((\\\\\\\\)*)(\\))",
      "endCaptures": {
        "1": { "name": "constant.character.escape.string.fish" },
        "3": { "name": "punctuation.definition.subshell.end.fish" }
      },
      "name": "meta.embedded.subshell.fish",
      "patterns": [
        { "include": "#string-double" },
        { "include": "#string-single" },
        { "include": "#comment" },
        { "include": "#keywords-subshell" },
        { "include": "#command-subshell" },
        { "include": "#io-redirection" },
        { "include": "#operators" },
        { "include": "#options" },
        { "include": "#subshell-bare" },
        { "include": "#subshell" },
        { "include": "#variable" },
        { "include": "#escape" }
      ]
    },
    "escape": {
      "patterns": [
        {
          "comment": "single character character escape sequences",
          "match": "\\\\[abefnrtv $*?~#(){}\\[\\]<>^&|;\"']",
          "name": "constant.character.escape.string.fish"
        },
        {
          "comment": "escapes the ascii character with the specified value (hexadecimal)",
          "match": "\\\\x[0-9a-fA-F]{1,2}",
          "name": "constant.character.escape.hex-ascii.fish"
        },
        {
          "comment": "escapes a byte of data with the specified value (hexadecimal). If you are using mutibyte encoding, this can be used to enter invalid strings. Only use this if you know what are doing.",
          "match": "\\\\X[0-9a-fA-F]{1,2}",
          "name": "constant.character.escape.hex-byte.fish"
        },
        {
          "comment": "escapes the ascii character with the specified value (octal)",
          "match": "\\\\[0-7]{1,3}",
          "name": "constant.character.escape.octal.fish"
        },
        {
          "comment": "escapes the 16-bit unicode character with the specified value (hexadecimal)",
          "match": "\\\\u[0-9a-fA-F]{1,4}",
          "name": "constant.character.escape.unicode-16-bit.fish"
        },
        {
          "comment": "escapes the 32-bit unicode character with the specified value (hexadecimal)",
          "match": "\\\\U[0-9a-fA-F]{1,8}",
          "name": "constant.character.escape.unicode-32-bit.fish"
        },
        {
          "comment": "escapes the control sequence generated by pressing the control key and the specified letter",
          "match": "\\\\c[a-zA-Z]",
          "name": "constant.character.escape.control.fish"
        }
      ]
    },
    "variable": {
      "patterns": [
        {
          "comment": "Built-in variables with slice",
          "begin": "(\\$)(argv|CMD_DURATION|COLUMNS|fish_bind_mode|fish_color_autosuggestion|fish_color_cancel|fish_color_command|fish_color_comment|fish_color_cwd|fish_color_cwd_root|fish_color_end|fish_color_error|fish_color_escape|fish_color_hg_added|fish_color_hg_clean|fish_color_hg_copied|fish_color_hg_deleted|fish_color_hg_dirty|fish_color_hg_modified|fish_color_hg_renamed|fish_color_hg_unmerged|fish_color_hg_untracked|fish_color_history_current|fish_color_host|fish_color_host_remote|fish_color_match|fish_color_normal|fish_color_operator|fish_color_param|fish_color_quote|fish_color_redirection|fish_color_search_match|fish_color_selection|fish_color_status|fish_color_user|fish_color_valid_path|fish_complete_path|fish_function_path|fish_greeting|fish_key_bindings|fish_pager_color_completion|fish_pager_color_description|fish_pager_color_prefix|fish_pager_color_progress|fish_pid|fish_prompt_hg_status_added|fish_prompt_hg_status_copied|fish_prompt_hg_status_deleted|fish_prompt_hg_status_modified|fish_prompt_hg_status_order|fish_prompt_hg_status_unmerged|fish_prompt_hg_status_untracked|FISH_VERSION|history|hostname|IFS|LINES|pipestatus|status|umask|version)\\b(?=\\[)",
          "beginCaptures": {
            "1": { "name": "punctuation.definition.variable.fish" },
            "2": { "name": "variable.language.fish" }
          },
          "end": "(?<=\\])",
          "name": "variable.language.fish",
          "patterns": [{ "include": "#slice" }]
        },
        {
          "comment": "Built-in variables without slice",
          "captures": {
            "1": { "name": "punctuation.definition.variable.fish" }
          },
          "match": "(\\$)(argv|CMD_DURATION|COLUMNS|fish_bind_mode|fish_color_autosuggestion|fish_color_cancel|fish_color_command|fish_color_comment|fish_color_cwd|fish_color_cwd_root|fish_color_end|fish_color_error|fish_color_escape|fish_color_hg_added|fish_color_hg_clean|fish_color_hg_copied|fish_color_hg_deleted|fish_color_hg_dirty|fish_color_hg_modified|fish_color_hg_renamed|fish_color_hg_unmerged|fish_color_hg_untracked|fish_color_history_current|fish_color_host|fish_color_host_remote|fish_color_match|fish_color_normal|fish_color_operator|fish_color_param|fish_color_quote|fish_color_redirection|fish_color_search_match|fish_color_selection|fish_color_status|fish_color_user|fish_color_valid_path|fish_complete_path|fish_function_path|fish_greeting|fish_key_bindings|fish_pager_color_completion|fish_pager_color_description|fish_pager_color_prefix|fish_pager_color_progress|fish_pid|fish_prompt_hg_status_added|fish_prompt_hg_status_copied|fish_prompt_hg_status_deleted|fish_prompt_hg_status_modified|fish_prompt_hg_status_order|fish_prompt_hg_status_unmerged|fish_prompt_hg_status_untracked|FISH_VERSION|history|hostname|IFS|LINES|pipestatus|status|umask|version)\\b",
          "name": "variable.language.fish"
        },
        {
          "comment": "Normal variables with slice",
          "begin": "(\\$)([a-zA-Z_][a-zA-Z0-9_]*)(?=\\[)",
          "beginCaptures": {
            "1": { "name": "punctuation.definition.variable.fish" },
            "2": { "name": "variable.other.normal.fish" }
          },
          "end": "(?<=\\])",
          "name": "variable.other.normal.fish",
          "patterns": [{ "include": "#slice" }]
        },
        {
          "comment": "Normal variables without slice",
          "captures": {
            "1": { "name": "punctuation.definition.variable.fish" }
          },
          "match": "(\\$)[a-zA-Z_][a-zA-Z0-9_]*",
          "name": "variable.other.normal.fish"
        }
      ]
    },
    "variable-string-double": {
      "patterns": [
        {
          "comment": "Built-in variables with slice inside double-quoted strings",
          "begin": "(\\$)(argv|CMD_DURATION|COLUMNS|fish_bind_mode|fish_color_autosuggestion|fish_color_cancel|fish_color_command|fish_color_comment|fish_color_cwd|fish_color_cwd_root|fish_color_end|fish_color_error|fish_color_escape|fish_color_hg_added|fish_color_hg_clean|fish_color_hg_copied|fish_color_hg_deleted|fish_color_hg_dirty|fish_color_hg_modified|fish_color_hg_renamed|fish_color_hg_unmerged|fish_color_hg_untracked|fish_color_history_current|fish_color_host|fish_color_host_remote|fish_color_match|fish_color_normal|fish_color_operator|fish_color_param|fish_color_quote|fish_color_redirection|fish_color_search_match|fish_color_selection|fish_color_status|fish_color_user|fish_color_valid_path|fish_complete_path|fish_function_path|fish_greeting|fish_key_bindings|fish_pager_color_completion|fish_pager_color_description|fish_pager_color_prefix|fish_pager_color_progress|fish_pid|fish_prompt_hg_status_added|fish_prompt_hg_status_copied|fish_prompt_hg_status_deleted|fish_prompt_hg_status_modified|fish_prompt_hg_status_order|fish_prompt_hg_status_unmerged|fish_prompt_hg_status_untracked|FISH_VERSION|history|hostname|IFS|LINES|pipestatus|status|umask|version)\\b(?=\\[)",
          "beginCaptures": {
            "1": { "name": "punctuation.definition.variable.fish" },
            "2": { "name": "variable.language.fish" }
          },
          "end": "(?<=\\])",
          "name": "variable.language.fish",
          "patterns": [{ "include": "#slice-string-double" }]
        },
        {
          "comment": "Built-in variables without slice inside double-quoted strings",
          "captures": {
            "1": { "name": "punctuation.definition.variable.fish" }
          },
          "match": "(\\$)(argv|CMD_DURATION|COLUMNS|fish_bind_mode|fish_color_autosuggestion|fish_color_cancel|fish_color_command|fish_color_comment|fish_color_cwd|fish_color_cwd_root|fish_color_end|fish_color_error|fish_color_escape|fish_color_hg_added|fish_color_hg_clean|fish_color_hg_copied|fish_color_hg_deleted|fish_color_hg_dirty|fish_color_hg_modified|fish_color_hg_renamed|fish_color_hg_unmerged|fish_color_hg_untracked|fish_color_history_current|fish_color_host|fish_color_host_remote|fish_color_match|fish_color_normal|fish_color_operator|fish_color_param|fish_color_quote|fish_color_redirection|fish_color_search_match|fish_color_selection|fish_color_status|fish_color_user|fish_color_valid_path|fish_complete_path|fish_function_path|fish_greeting|fish_key_bindings|fish_pager_color_completion|fish_pager_color_description|fish_pager_color_prefix|fish_pager_color_progress|fish_pid|fish_prompt_hg_status_added|fish_prompt_hg_status_copied|fish_prompt_hg_status_deleted|fish_prompt_hg_status_modified|fish_prompt_hg_status_order|fish_prompt_hg_status_unmerged|fish_prompt_hg_status_untracked|FISH_VERSION|history|hostname|IFS|LINES|pipestatus|status|umask|version)\\b",
          "name": "variable.language.fish"
        },
        {
          "comment": "Normal variables with slice inside double-quoted strings",
          "begin": "(\\$)([a-zA-Z_][a-zA-Z0-9_]*)(?=\\[)",
          "beginCaptures": {
            "1": { "name": "punctuation.definition.variable.fish" },
            "2": { "name": "variable.other.normal.fish" }
          },
          "end": "(?<=\\])",
          "name": "variable.other.normal.fish",
          "patterns": [{ "include": "#slice-string-double" }]
        },
        {
          "comment": "Normal variables without slice inside double-quoted strings",
          "captures": {
            "1": { "name": "punctuation.definition.variable.fish" }
          },
          "match": "(\\$)[a-zA-Z_][a-zA-Z0-9_]*",
          "name": "variable.other.normal.fish"
        }
      ]
    }
  },
  "scopeName": "source.fish",
  "uuid": "9CA6DB6F-A16F-4836-A058-617C7378775D"
}
