aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bash/bash_completion.d/git.bash35
-rw-r--r--readline/inputrc6
2 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..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
diff --git a/readline/inputrc b/readline/inputrc
index c11d8fe7..857952cd 100644
--- a/readline/inputrc
+++ b/readline/inputrc
@@ -62,6 +62,12 @@ $if Bash
# Alt+A cycles through completion options
"\ea": menu-complete
+ # Special completion keys for git(1)
+ ## Branches
+ "\C-xb": complete
+ ## Tags
+ "\C-xt": complete
+
# Ctrl-Alt-L to clear screen; more ksh-like
"\e\C-l": clear-screen