What steps will reproduce the bug?
- Install bat + fish with
fish-autopair on (autopair binds <TAB> to _autopair_tab, which calls commandline --function complete).
- Run fish interactively.
- Type
bat -l and press <TAB>.
What happens?
bat -l><TAB> aborts with:
/usr/share/fish/vendor_completions.d/bat.fish (line 1): expanded command is empty
command $bat --list-languages
followed by:
for spec in (command $bat --list-languages) # invalid command name
The language list is never shown.
What did you expect to happen instead?
bat -l><TAB> should list the available --language values (extensions → syntax names), as it does when <TAB> is bound to fish's default complete instead of _autopair_tab.
How did you install bat?
Arch Linux (CachyOS) package: bat 0.26.1-2.1.
Root cause (analysis)
completions/bat.fish line 6 declares:
bat is a non-exported global variable. When the completion options are evaluated, e.g. inside:
complete -c $bat -l language -x -a "(__bat_complete_list_languages)"
and the completion query is re-evaluated from a subshell (which is exactly what _autopair_tab's commandline --function complete does), the non-exported $bat is not visible in the child process, so $bat expands to empty → command --list-languages is an empty command.
With fish's default <TAB> binding (bound directly to complete), the same completion is evaluated in-process where the global $bat IS visible, so it works — which is why this is hard to reproduce without a custom Tab binding.
A more robust fix would be to not depend on a non-exported variable, e.g. compute the command inline per use:
set -l b (command -v bat; or echo batcat)
or export it (set -gx bat bat). On Debian/Ubuntu where the binary is batcat, the command-detection variant is preferable.
(For reference, the fish-autopair side is https://github.com/jorgebucaran/autopair.fish — _autopair_tab.)
bat version and environment
#### Software version
bat 0.26.1 (v0.25.0-402-g979ba226)
#### Operating system
- OS: Linux (CachyOS Linux rolling)
- Kernel: 7.2.2-1-cachyos-bore-lto
#### Command-line
bat --diagnostic
#### Environment variables
BAT_CACHE_PATH=<not set>
BAT_CONFIG_PATH=<not set>
BAT_OPTS=<not set>
BAT_PAGER=<not set>
BAT_PAGING=<not set>
BAT_STYLE=<not set>
BAT_TABS=<not set>
BAT_THEME=<not set>
COLORTERM=truecolor
LANG=zh_CN.UTF-8
LC_ALL=<not set>
LESS=<not set>
MANPAGER='sh -c '\''col -bx | bat -l man -p'\'''
NO_PROXY=127.0.0.1,localhost,::1
no_proxy=127.0.0.1,localhost,::1
NO_COLOR=<not set>
PAGER=<not set>
SHELL=/usr/bin/fish
TERM=xterm-256color
XDG_CACHE_HOME=/home/recluse/.cache
XDG_CONFIG_HOME=/home/recluse/.config
#### Compile time information
- Profile: release
- Target triple: x86_64-unknown-linux-gnu
- Family: unix
- OS: linux
- Architecture: x86_64
- Pointer width: 64
- Endian: little
- CPU features: avx,avx2,avx512bw,avx512cd,avx512dq,avx512f,avx512vl,bmi1,bmi2,cmpxchg16b,f16c,fma,fxsr,lzcnt,movbe,popcnt,sse,sse2,sse3,sse4.1,sse4.2,ssse3,xsave
- Host: x86_64-unknown-linux-gnu
#### Less version
less 704 (PCRE2 regular expressions)
What steps will reproduce the bug?
fish-autopairon (autopair binds<TAB>to_autopair_tab, which callscommandline --function complete).bat -land press<TAB>.What happens?
bat -l><TAB>aborts with:followed by:
The language list is never shown.
What did you expect to happen instead?
bat -l><TAB>should list the available--languagevalues (extensions → syntax names), as it does when<TAB>is bound to fish's defaultcompleteinstead of_autopair_tab.How did you install
bat?Arch Linux (CachyOS) package:
bat 0.26.1-2.1.Root cause (analysis)
completions/bat.fishline 6 declares:set bat batbatis a non-exported global variable. When the completion options are evaluated, e.g. inside:and the completion query is re-evaluated from a subshell (which is exactly what
_autopair_tab'scommandline --function completedoes), the non-exported$batis not visible in the child process, so$batexpands to empty →command --list-languagesis an empty command.With fish's default
<TAB>binding (bound directly tocomplete), the same completion is evaluated in-process where the global$batIS visible, so it works — which is why this is hard to reproduce without a custom Tab binding.A more robust fix would be to not depend on a non-exported variable, e.g. compute the command inline per use:
or export it (
set -gx bat bat). On Debian/Ubuntu where the binary isbatcat, the command-detection variant is preferable.(For reference, the fish-autopair side is https://github.com/jorgebucaran/autopair.fish —
_autopair_tab.)bat version and environment