2015-07-16 17:32:23 +00:00
|
|
|
# Use git-annex's built-in bash completion
|
2018-11-12 17:23:05 +00:00
|
|
|
# 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!
|
2015-07-20 14:56:08 +00:00
|
|
|
_git-annex()
|
|
|
|
{
|
2017-06-09 15:30:24 +00:00
|
|
|
local CMDLINE
|
|
|
|
local IFS=$'\n'
|
2015-07-20 14:56:08 +00:00
|
|
|
CMDLINE=(--bash-completion-index $COMP_CWORD)
|
|
|
|
|
|
|
|
for arg in ${COMP_WORDS[@]}; do
|
|
|
|
CMDLINE=(${CMDLINE[@]} --bash-completion-word $arg)
|
|
|
|
done
|
|
|
|
|
|
|
|
COMPREPLY=( $(git-annex "${CMDLINE[@]}") )
|
|
|
|
}
|
|
|
|
|
|
|
|
complete -o bashdefault -o default -o filenames -F _git-annex git-annex
|
2015-07-16 17:32:23 +00:00
|
|
|
|
|
|
|
# Called by git's bash completion script when completing "git annex"
|
2018-11-12 17:23:05 +00:00
|
|
|
# Translate to the "git-annex" completion above.
|
2015-07-16 17:32:23 +00:00
|
|
|
_git_annex() {
|
2018-11-12 17:23:05 +00:00
|
|
|
local CMDLINE
|
2015-07-16 17:32:23 +00:00
|
|
|
CMDLINE=(--bash-completion-index $(($COMP_CWORD - 1)))
|
|
|
|
|
|
|
|
local seen_git
|
|
|
|
local seen_annex
|
|
|
|
for arg in ${COMP_WORDS[@]}; do
|
|
|
|
if [ "$arg" = git ] && [ -z "$seen_git" ]; then
|
|
|
|
seen_git=1
|
|
|
|
CMDLINE=(${CMDLINE[@]} --bash-completion-word git-annex)
|
|
|
|
elif [ "$arg" = annex ] && [ -z "$seen_annex" ]; then
|
|
|
|
seen_annex=1
|
|
|
|
else
|
|
|
|
CMDLINE=(${CMDLINE[@]} --bash-completion-word $arg)
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2018-11-12 17:23:05 +00:00
|
|
|
# This is the same as __gitcomp_file_direct in git-completion.bash;
|
|
|
|
local IFS=$'\n'
|
2015-07-16 17:32:23 +00:00
|
|
|
COMPREPLY=( $(git-annex "${CMDLINE[@]}") )
|
2018-11-12 17:23:05 +00:00
|
|
|
compopt -o filenames +o nospace ||
|
|
|
|
compgen -f /non-existing-dir/ >/dev/null ||
|
|
|
|
true
|
2015-07-16 17:32:23 +00:00
|
|
|
}
|