1
0
mirror of https://github.com/sharkdp/bat synced 2026-06-09 10:03:18 +00:00

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.
This commit is contained in:
truffle
2026-05-10 09:19:54 +00:00
parent f74082cee8
commit 5f952066fb
2 changed files with 7 additions and 1 deletions
+1
View File
@@ -43,6 +43,7 @@
- Fixed bug caused by using `--plain` and `--terminal-width=N` flags simultaneously, see #3529 (@H4k1l) - Fixed bug caused by using `--plain` and `--terminal-width=N` flags simultaneously, see #3529 (@H4k1l)
- Fixed syntax tests path, see #3610 (@foxfromworld) - 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 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 ## Other
- Use git version of cross. See #3533 (@OctopusET) - Use git version of cross. See #3533 (@OctopusET)
+6 -1
View File
@@ -90,7 +90,12 @@ _{{PROJECT_EXECUTABLE}}_main() {
languages) languages)
local IFS=$'\n' local IFS=$'\n'
local -a languages 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 _describe 'language' languages && ret=0
;; ;;