fix Bash completion on macOS (#2074)

* fix Bash completion on macOS

The Homebrew-provided bash-completion is version 1.x,
which doesn't provide _init_completion. We add a standard
shim instead.

* Add entry to CHANGELOG

* Update CHANGELOG.md

Co-authored-by: Ville Skyttä <ville.skytta@iki.fi>

* review: avoid calling _split_longopt repeatedly

Co-authored-by: Ville Skyttä <ville.skytta@iki.fi>
This commit is contained in:
Josh Pencheon 2022-02-24 06:57:23 +00:00 committed by GitHub
parent e4f6fb2afe
commit ad6cae433a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View File

@ -7,6 +7,8 @@
## Bugfixes
- Fix bash completion on bash 3.x and bash-completion 1.x. See #2066 (@joshpencheon)
## Other
## Syntaxes

View File

@ -2,9 +2,22 @@
# Requires https://github.com/scop/bash-completion
# Macs have bash3 for which the bash-completion package doesn't include
# _init_completion. This is a minimal version of that function.
__bat_init_completion()
{
COMPREPLY=()
_get_comp_words_by_ref "$@" cur prev words cword
}
_bat() {
local cur prev words cword split
_init_completion -s || return 0
local cur prev words cword split=false
if declare -F _init_completion >/dev/null 2>&1; then
_init_completion -s || return 0
else
__bat_init_completion -n "=" || return 0
_split_longopt && split=true
fi
if [[ ${words[1]-} == cache ]]; then
case $prev in