aboutsummaryrefslogtreecommitdiff
path: root/bash/bashrc.d/git.bash
diff options
context:
space:
mode:
Diffstat (limited to 'bash/bashrc.d/git.bash')
-rw-r--r--bash/bashrc.d/git.bash21
1 files changed, 8 insertions, 13 deletions
diff --git a/bash/bashrc.d/git.bash b/bash/bashrc.d/git.bash
index 5965607c..182cef46 100644
--- a/bash/bashrc.d/git.bash
+++ b/bash/bashrc.d/git.bash
@@ -1,27 +1,22 @@
# Completion for git local branch names
_git() {
- # Bail if not a git repo (or no git!)
- if ! git rev-parse --git-dir >/dev/null 2>&1 ; then
- return 1
- fi
+ # Use default completion if no matches
+ compopt -o default
- # Get current and previous word
- local word first
- word=${COMP_WORDS[COMP_CWORD]}
- first=${COMP_WORDS[1]}
+ # Bail if not a git repo (or no git!)
+ git rev-parse --git-dir >/dev/null 2>&1 || return 1
# Switch on the previous word
- case $first in
+ case ${COMP_WORDS[1]} in
# If the first word is appropriate, complete with branch/tag names
checkout|merge|rebase)
- local -a branches
local branch
while read -r branch ; do
- branches=("${branches[@]}" "${branch##*/}")
+ [[ $branch == "${COMP_WORDS[COMP_CWORD]}"* ]] || continue
+ COMPREPLY=("${COMPREPLY[@]}" "$branch")
done < <(git for-each-ref refs/{heads,tags} 2>/dev/null)
- COMPREPLY=( $(compgen -W "${branches[*]}" -- "$word") )
return
;;
@@ -31,5 +26,5 @@ _git() {
;;
esac
}
-complete -F _git -o default git
+complete -F _git git