Skip to content

Commit

Permalink
Update the bash completion script
Browse files Browse the repository at this point in the history
I haven't run git blame, but this script hasn't been updated in a while.
Apparently development in 'bash-completion' is moving a lot faster now,
so supporting multiple mutually-incompatible versions of it has become
necessary.

For some reason, this issue wasn't caught on CI - I think the newer
'bash-completion' hasn't reached the distribution used there.  Still,
this code is now forward-compatible.
  • Loading branch information
Arav K. committed Jun 13, 2024
1 parent d7bf28d commit b1b7230
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions beets/ui/completion_base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
# plugins dynamically
#
# Currently, only Bash 3.2 and newer is supported and the
# `bash-completion` package is required.
# `bash-completion` package (v2.10 or newer) is required.
#
# TODO
# ----
Expand All @@ -47,14 +47,34 @@
# completion package can handle this.
#

if [[ ${BASH_COMPLETION_VERSINFO[0]} -ne 2 \
|| ${BASH_COMPLETION_VERSINFO[1]} -lt 10 ]]; then
echo "Incompatible version of 'bash-completion'!"
return 1
fi

# The following functions are introduced by bash-completion v2.12, and
# at the same time the functions they replace are deprecated. In order
# to avoid using deprecated functions, here are some forward-compatible
# aliases which use the deprecated functions when necessary.

if [[ ${BASH_COMPLETION_VERSINFO[1]} -lt 12 ]]; then
_comp_get_words() {
_get_comp_words_by_ref "$@"
}

_comp_compgen_filedir() {
_filedir "$@"
}
fi

# Determines the beets subcommand and dispatches the completion
# accordingly.
_beet_dispatch() {
local cur prev cmd=

COMPREPLY=()
_get_comp_words_by_ref -n : cur prev
_comp_get_words -n : cur prev

# Look for the beets subcommand
local arg
Expand Down Expand Up @@ -99,7 +119,7 @@ _beet_complete() {
completions="${flags___common} ${opts} ${flags}"
COMPREPLY+=( $(compgen -W "$completions" -- $cur) )
else
_filedir
_comp_compgen_filedir
fi
}

Expand All @@ -114,12 +134,12 @@ _beet_complete_global() {
;;
-l|--library|-c|--config)
# Filename completion
_filedir
_comp_compgen_filedir
return
;;
-d|--directory)
# Directory completion
_filedir -d
_comp_compgen_filedir -d
return
;;
esac
Expand Down

0 comments on commit b1b7230

Please sign in to comment.