aboutsummaryrefslogtreecommitdiff
path: root/bash-completion
diff options
context:
space:
mode:
Diffstat (limited to 'bash-completion')
-rw-r--r--bash-completion/gitbcheckout14
-rw-r--r--bash-completion/gitbmerge27
2 files changed, 24 insertions, 17 deletions
diff --git a/bash-completion/gitbcheckout b/bash-completion/gitbcheckout
new file mode 100644
index 0000000..a3c1d8e
--- /dev/null
+++ b/bash-completion/gitbcheckout
@@ -0,0 +1,14 @@
+_gitbcheckout() {
+ [ "$COMP_CWORD" -gt 1 ] && return # Complete only single branch
+ local cur prev words cword
+ _init_completion || return
+ local gdir branch
+ gdir="$(git rev-parse --git-common-dir 2>/dev/null)" || return
+ local branches=()
+ # TODO ignore current HEAD (merging HEAD to HEAD does not makes sense)
+ while read -r branch; do
+ branches+=("$branch")
+ done < <(find "$gdir/refs/heads" "$gdir/refs/remotes" -mindepth 1 -printf '%P\n')
+ COMPREPLY=($(compgen -W "${branches[*]}" -- ${cur}))
+}
+complete -F _gitbcheckout gitbcheckout
diff --git a/bash-completion/gitbmerge b/bash-completion/gitbmerge
index 8706fc8..33e8ed0 100644
--- a/bash-completion/gitbmerge
+++ b/bash-completion/gitbmerge
@@ -1,21 +1,14 @@
_gitbmerge() {
- local cur prev
+ [ "$COMP_CWORD" -gt 1 ] && return # Complete only single branch
+ local cur prev words cword
_init_completion || return
- [ $COMP_CWORD -gt 1 ] && return # Complete only single dependency
- COMPREPLY=()
- local GDIR="$(pwd)"
- while [ ! -d "$GDIR/.git" ]; do
- [ -z "$GDIR" ] && return
- GDIR="${GDIR%/*}"
- done
- GDIR="$GDIR/.git"
- [ -f "$GDIR" ] && GDIR="$(cat "$GDIR")" # This just points to some other directory
- [ -d "$GDIR/refs/heads" ] || return # No completion if there is no local branch
- local ops=""
- for B in "$GDIR"/refs/heads/*; do
- # TODO skip branch on HEAD
- ops="$ops ${B#$GDIR/refs/heads/}"
- done
- COMPREPLY+=($(compgen -W "${ops}" -- ${cur}))
+ local gdir branch
+ gdir="$(git rev-parse --git-common-dir 2>/dev/null)" || return
+ local branches=()
+ # TODO ignore current HEAD (merging HEAD to HEAD does not makes sense)
+ while read -r branch; do
+ branches+=("$branch")
+ done < <(find "$gdir/refs/heads" -mindepth 1 -printf '%P\n')
+ COMPREPLY=($(compgen -W "${branches[*]}" -- ${cur}))
}
complete -F _gitbmerge gitbmerge