aboutsummaryrefslogtreecommitdiff
path: root/bash-completion/gitbcheckout
blob: a3c1d8e212d09f1bf88aeb44ede6d4c047eaea98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
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