From 5f952066fb6196c33862d39e7fdf9f0f5960f5a2 Mon Sep 17 00:00:00 2001 From: truffle Date: Sun, 10 May 2026 09:19:54 +0000 Subject: [PATCH 1/3] fix: only offer language names in zsh tab completion for `-l` The previous awk script in `bat.zsh.in` split each line of `bat --list-languages` on `:` or `,` and emitted every field as a completion candidate, including the second column. That column lists file matchers, which can be plain extensions (`rs`), globs (`*.rs`), absolute paths (`/etc/profile`), or filenames (`Containerfile`). None of those parse as `-l` arguments, so completing them produces `unknown syntax` errors. Switch to splitting on `:` only and emit the language name as the completion value with the file-matcher list as its description, which matches the bash completion's behavior. Closes #3735. --- CHANGELOG.md | 1 + assets/completions/bat.zsh.in | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 89789c54..4e8e8531 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ - Fixed bug caused by using `--plain` and `--terminal-width=N` flags simultaneously, see #3529 (@H4k1l) - Fixed syntax tests path, see #3610 (@foxfromworld) - Fix zsh tab completion word-splitting language names containing spaces (e.g. `HTML (Jinja2)`, `Apache Conf`), see #3693 (@YoshKoz) +- Fix zsh tab completion offering invalid `-l` arguments (file globs, paths, hidden filenames) sourced from the second column of `--list-languages`. Closes #3735, see #PR_NUMBER (@truffle-dev) ## Other - Use git version of cross. See #3533 (@OctopusET) diff --git a/assets/completions/bat.zsh.in b/assets/completions/bat.zsh.in index 4fddcbb4..3991b996 100644 --- a/assets/completions/bat.zsh.in +++ b/assets/completions/bat.zsh.in @@ -90,7 +90,12 @@ _{{PROJECT_EXECUTABLE}}_main() { languages) local IFS=$'\n' local -a languages - languages=( ${(f)"$({{PROJECT_EXECUTABLE}} --color=never --decorations=never --list-languages | awk -F':|,' '{ for (i = 1; i <= NF; ++i) printf("%s:%s\n", $i, $1) }')"} ) + # Only offer language names as completion values. The second column + # of `--list-languages` mixes plain extensions with globs (`*.rs`), + # absolute paths (`/etc/profile`), and full filenames + # (`Containerfile`); none of those parse as `-l` arguments. See + # https://github.com/sharkdp/bat/issues/3735. + languages=( ${(f)"$({{PROJECT_EXECUTABLE}} --color=never --decorations=never --list-languages | awk -F: '{ printf("%s:%s\n", $1, $2) }')"} ) _describe 'language' languages && ret=0 ;; From 98df25434e8bf160edfab5bae0c978df9766207d Mon Sep 17 00:00:00 2001 From: truffle Date: Sun, 10 May 2026 09:20:40 +0000 Subject: [PATCH 2/3] fix: reference PR number in changelog entry --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e8e8531..81f36a38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,7 +43,7 @@ - Fixed bug caused by using `--plain` and `--terminal-width=N` flags simultaneously, see #3529 (@H4k1l) - Fixed syntax tests path, see #3610 (@foxfromworld) - Fix zsh tab completion word-splitting language names containing spaces (e.g. `HTML (Jinja2)`, `Apache Conf`), see #3693 (@YoshKoz) -- Fix zsh tab completion offering invalid `-l` arguments (file globs, paths, hidden filenames) sourced from the second column of `--list-languages`. Closes #3735, see #PR_NUMBER (@truffle-dev) +- Fix zsh tab completion offering invalid `-l` arguments (file globs, paths, hidden filenames) sourced from the second column of `--list-languages`. Closes #3735, see #3737 (@truffle-dev) ## Other - Use git version of cross. See #3533 (@OctopusET) From 138d70fd4c93759a444c0c9fcc885a0c2202f9d5 Mon Sep 17 00:00:00 2001 From: truffle Date: Sun, 10 May 2026 14:10:54 +0000 Subject: [PATCH 3/3] fix(zsh): drop redundant awk pipeline in language completion `bat --list-languages` already emits each entry in `name:matchers` form, which is the format `_describe` consumes directly. The previous awk script split each line on `:` and re-emitted `$1:$2`, which is byte-identical to the input. Verified with `diff <(bat --list-languages) <(bat --list-languages | awk -F: '{ printf("%s:%s\\n", $1, $2) }')` against the current syntax set. --- assets/completions/bat.zsh.in | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/assets/completions/bat.zsh.in b/assets/completions/bat.zsh.in index 3991b996..efdb185e 100644 --- a/assets/completions/bat.zsh.in +++ b/assets/completions/bat.zsh.in @@ -90,12 +90,12 @@ _{{PROJECT_EXECUTABLE}}_main() { languages) local IFS=$'\n' local -a languages - # Only offer language names as completion values. The second column - # of `--list-languages` mixes plain extensions with globs (`*.rs`), - # absolute paths (`/etc/profile`), and full filenames - # (`Containerfile`); none of those parse as `-l` arguments. See + # `--list-languages` emits one `name:matchers` line per language, + # which `_describe` parses as `value:description`. Only the + # language name is offered as the completion value; the matchers + # show up as the menu description. See # https://github.com/sharkdp/bat/issues/3735. - languages=( ${(f)"$({{PROJECT_EXECUTABLE}} --color=never --decorations=never --list-languages | awk -F: '{ printf("%s:%s\n", $1, $2) }')"} ) + languages=( ${(f)"$({{PROJECT_EXECUTABLE}} --color=never --decorations=never --list-languages)"} ) _describe 'language' languages && ret=0 ;;