aboutsummaryrefslogtreecommitdiff
path: root/bash
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2018-12-06 13:36:38 +1300
committerTom Ryder <tom@sanctum.geek.nz>2018-12-06 13:36:38 +1300
commitad1ec8eb97907f17282ffe465fce036b09d44699 (patch)
tree4d0b1a256f7356aca95da92bf48b5ae39860c800 /bash
parentMerge branch 'release/v3.1.0' into develop (diff)
downloaddotfiles-ad1ec8eb97907f17282ffe465fce036b09d44699.tar.gz
dotfiles-ad1ec8eb97907f17282ffe465fce036b09d44699.zip
Apply much simpler completion to Git
Use CTRL-X, B to complete branch names, and CTRL-X, T to complete tag names. It's too complicated to do it contextually, and it's all I really wanted anyway.
Diffstat (limited to 'bash')
-rw-r--r--bash/bash_completion.d/git.bash35
1 files changed, 35 insertions, 0 deletions
diff --git a/bash/bash_completion.d/git.bash b/bash/bash_completion.d/git.bash
new file mode 100644
index 00000000..450160fc
--- /dev/null
+++ b/bash/bash_completion.d/git.bash
@@ -0,0 +1,35 @@
+# Complete Git with branch names or tag names if specific keys are used, but
+# fall back on filenames otherwise; it's too complicated to be worth trying to
+# do it all contextually
+
+# Requires Bash >=4.0 for COMP_KEY
+((BASH_VERSINFO[0] >= 4)) || continue
+
+# Define and set helper function
+_git() {
+
+ # What completion to do
+ case $COMP_KEY in
+
+ # Complete with branch names if C-x,B is pressed
+ 98)
+ local ci
+ while read -r _ ref ; do
+ COMPREPLY[ci++]=${ref#refs/heads/}
+ done < <(git show-ref --heads)
+ ;;
+
+ # Complete with tag names if C-x,T is pressed
+ 116)
+ local ci
+ while read -r _ ref ; do
+ COMPREPLY[ci++]=${ref#refs/tags/}
+ done < <(git show-ref --tags)
+ ;;
+
+ # Do no completion, so we fall back on filenames
+ *) return 1 ;;
+
+ esac
+}
+complete -F _git -o bashdefault -o default git