summaryrefslogtreecommitdiff
path: root/bash-completion.bash
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-07-20 10:56:08 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-07-20 11:17:35 -0400
commitb0225575c77ae73ffd74b4ffecd4c35846f91e7a (patch)
treee6d04e6d7f996cabd5109ea27319d4b3669f895b /bash-completion.bash
parentc1ad287fa179f593cd91d6e1af3b53d34e9008cd (diff)
fix bash completion of filenames containing spaces
Work around https://github.com/pcapriotti/optparse-applicative/issues/146 by not using action "file" and instead passing -o bashdefault -o default to complete. This way, when optparse fails to complete a filename, bash will fall back to regular filename completion. Unfortunately, optparse-applicative does not provide a way to control the options passed to complete, so I had to modify its generated completion script. Note that for "git annex" command completion, git's completion script already used -o bashdefault -o default, so that works too.
Diffstat (limited to 'bash-completion.bash')
-rw-r--r--bash-completion.bash14
1 files changed, 13 insertions, 1 deletions
diff --git a/bash-completion.bash b/bash-completion.bash
index b0367c030..11f9ff810 100644
--- a/bash-completion.bash
+++ b/bash-completion.bash
@@ -1,7 +1,19 @@
# 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!
-source <(git-annex --bash-completion-script git-annex)
+_git-annex()
+{
+ local cmdline
+ 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
# Called by git's bash completion script when completing "git annex"
_git_annex() {