bash completion fix

Fix bash completion of "git annex" to propertly handle files with spaces
and other problem characters. (Completion of "git-annex" already did.)

This commit was sponsored by Jake Vosloo on Patreon.
This commit is contained in:
Joey Hess 2018-11-12 13:23:05 -04:00
parent d01c7c173c
commit 5ce078da92
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
4 changed files with 41 additions and 3 deletions

View file

@ -1,6 +1,6 @@
# Use git-annex's built-in bash completion
# This bash completion is generated by the option parser, so it covers all
# commands, all options, and will never go out of date!
# This is the same code output by git-annex --bash-completion-script git-annex
# This covers all commands, all options, and will never go out of date!
_git-annex()
{
local CMDLINE
@ -17,8 +17,9 @@ _git-annex()
complete -o bashdefault -o default -o filenames -F _git-annex git-annex
# Called by git's bash completion script when completing "git annex"
# Translate to the "git-annex" completion above.
_git_annex() {
local cmdline
local CMDLINE
CMDLINE=(--bash-completion-index $(($COMP_CWORD - 1)))
local seen_git
@ -34,5 +35,10 @@ _git_annex() {
fi
done
# This is the same as __gitcomp_file_direct in git-completion.bash;
local IFS=$'\n'
COMPREPLY=( $(git-annex "${CMDLINE[@]}") )
compopt -o filenames +o nospace ||
compgen -f /non-existing-dir/ >/dev/null ||
true
}