aboutsummaryrefslogtreecommitdiff
path: root/bash/bashrc.d
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2014-02-04 12:57:30 +1300
committerTom Ryder <tom@sanctum.geek.nz>2014-02-04 12:57:30 +1300
commit534a254fd11dbc7a1fd7d667119086fefef60598 (patch)
tree0dd9c83da30d211723b2623b4a0155bcfae0b4d3 /bash/bashrc.d
parentCorrect module definition for argumentative (diff)
downloaddotfiles-534a254fd11dbc7a1fd7d667119086fefef60598.tar.gz
dotfiles-534a254fd11dbc7a1fd7d667119086fefef60598.zip
Basic branch/tag completion for git(1)
Diffstat (limited to 'bash/bashrc.d')
-rw-r--r--bash/bashrc.d/git.bash39
1 files changed, 39 insertions, 0 deletions
diff --git a/bash/bashrc.d/git.bash b/bash/bashrc.d/git.bash
new file mode 100644
index 00000000..91b46f2a
--- /dev/null
+++ b/bash/bashrc.d/git.bash
@@ -0,0 +1,39 @@
+# Bail if no git(1)
+if ! hash git 2>/dev/null; then
+ return
+fi
+
+# Completion for git local branch names
+_git() {
+
+ # Bail if not a git repo
+ if ! git rev-parse --git-dir >/dev/null 2>&1 ; then
+ return 1
+ fi
+
+ # Get current and previous word
+ local word=${COMP_WORDS[COMP_CWORD]}
+ local prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ # Switch on the previous word
+ case $prev in
+
+ # If the previous word is appropriate, complete with branch/tag names
+ checkout|merge|rebase)
+ local -a branches
+ local branch
+ while read -r branch ; do
+ branches=("${branches[@]}" "${branch##*/}")
+ done < <(git for-each-ref refs/{heads,tags} 2>/dev/null)
+ COMPREPLY=( $(compgen -W "${branches[*]}" -- "$word") )
+ return
+ ;;
+
+ # Bail if it isn't
+ *)
+ return 1
+ ;;
+ esac
+}
+complete -F _git -o default git
+