fix: only offer language names in zsh tab completion for -l#3737
Conversation
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 sharkdp#3735.
|
The patch works for me. I initially thought the right fix would be not pulling in the built-in mappings, I particularly like the reduced number of items to choose from, less duplicated Bad thing, a value like So I am ok with it.
There are no zsh completion tests. EDIT1: syntect note updated |
| # 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) }')"} ) |
There was a problem hiding this comment.
wouldn't the awk part become redundant ?
`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.
|
Yes, you're right. I verified against the current syntax set: Dropped the awk and refreshed the comment in 138d70f. |
…anguage-only fix: only offer language names in zsh tab completion for `-l`
Closes #3735.
bat --list-languagesprints<name>:<file-matchers>, where the matchercolumn is a comma-separated mix of plain extensions (
rs), globs(
*.rs), absolute paths (/etc/profile), and full filenames(
Containerfile). The zsh completion's awk script split each line on:or,and emitted every field as a completion value, so tabcompletion offered candidates that
-lcannot parse:Switch to splitting on
:only, emit the language name as thecompletion value, and use the matcher list as its description. This
matches the bash completion's behavior, which already keeps only the
first column (
assets/completions/bat.bash.in:80-89).After the change, the completion menu shows just language names with
their extensions as descriptive context:
Verified locally with
cargo buildandcargo test --test integration_tests -- --test-threads=1(232 passed). Unit tests (cargo test --lib) also pass (124).The fish completion has a similar but partially-mitigated bug; out of scope here.