aboutsummaryrefslogtreecommitdiff
path: root/bash-completion.bash
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-07-16 13:32:23 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-07-16 13:32:23 -0400
commit94c8afbfec3c47132b106eb98bbf59defeef449f (patch)
treec0f4169419256e07992db001633c412f85ffc46d /bash-completion.bash
parentfe70e063d020dcc9d74edae7b7e3b3db2b089c66 (diff)
got bash completion working for "git annex" not just "git-annex"
This needs a patch to git to cause the git-annex completion to be auto-loaded when completing "git annex <tab>". Otherwise, it will only load when "git-annex" is tab completed. Once loaded, it works for both uses. I've submitted the git patch to the git mailing list.
Diffstat (limited to 'bash-completion.bash')
-rw-r--r--bash-completion.bash25
1 files changed, 25 insertions, 0 deletions
diff --git a/bash-completion.bash b/bash-completion.bash
new file mode 100644
index 000000000..b0367c030
--- /dev/null
+++ b/bash-completion.bash
@@ -0,0 +1,25 @@
+# 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)
+
+# Called by git's bash completion script when completing "git annex"
+_git_annex() {
+ local cmdline
+ 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
+
+ COMPREPLY=( $(git-annex "${CMDLINE[@]}") )
+}