aboutsummaryrefslogtreecommitdiff
path: root/bash/bash_completion.d/git.bash
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2018-12-14 13:14:00 +1300
committerTom Ryder <tom@sanctum.geek.nz>2018-12-14 13:14:00 +1300
commite0ff7ac01d6439d826ff9ef6f134a7638ade714f (patch)
tree781004065fefcbfd8e543a61de3d168383e71bde /bash/bash_completion.d/git.bash
parentMerge branch 'release/v3.1.0' (diff)
parentBump VERSION (diff)
downloaddotfiles-38fa4c8e4f2a2a185777f9438cccbb5f6dadc092.tar.gz (sig)
dotfiles-38fa4c8e4f2a2a185777f9438cccbb5f6dadc092.zip
Merge branch 'release/v3.2.0'v3.2.0
* release/v3.2.0: Bump VERSION Refactor some conditionals Factor out zsh ENV hack into one file Refactor "path list" not to require a subshell Correct completion for deep pass(1) directories Move filetype.vim helper funcs into autoload Fix a local var name in openssl(1ssl) completion Correct a variable ref in openssl(1ssl) completion Disable shellcheck rules for missed definition Add filenames treatment to mex(1df) completion Remove unneeded declaration Refactor some completions to avoid loops Remove unneeded stdout redirect Remove unneeded semicolon from sh "for VAR ; do" Substitute bad `continue` for `return` Add actual completion matching to git completion Apply much simpler completion to Git
Diffstat (limited to 'bash/bash_completion.d/git.bash')
-rw-r--r--bash/bash_completion.d/git.bash41
1 files changed, 41 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..c3a4d49c
--- /dev/null
+++ b/bash/bash_completion.d/git.bash
@@ -0,0 +1,41 @@
+# 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)) || return
+
+# 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
+ branch=${ref#refs/heads/}
+ case $branch in
+ "$2"*) COMPREPLY[ci++]=$branch ;;
+ esac
+ done < <(git show-ref --heads)
+ ;;
+
+ # Complete with tag names if C-x,T is pressed
+ 116)
+ local ci
+ while read -r _ ref ; do
+ tag=${ref#refs/tags/}
+ case $tag in
+ "$2"*) COMPREPLY[ci++]=$tag ;;
+ esac
+ 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