-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.git_completion.bash
More file actions
34 lines (31 loc) · 843 Bytes
/
Copy path.git_completion.bash
File metadata and controls
34 lines (31 loc) · 843 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env bash
_git_branch_completions() {
local cur prev branches line
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
case "${cur}" in
-*)
# specify switches.
COMPREPLY=( $(compgen -W '-t -b -m --set-upstream-to' -- $cur))
return 0
;;
esac
case "${prev}" in
-t|-b|branch|checkout)
# Specify only the local branches.
branches=$(git branch | sed -e 's/*//')
COMPREPLY=( $(compgen -W "${branches}" -- ${cur}) )
return 0
;;
git)
# Specify git subcommands.
COMPREPLY=( $(compgen -W "add branch checkout commit rebase rm" -- ${cur}))
;;
*)
# anything else, fall back to filenames to auto-complete.
COMPREPLY=( $(compgen -f -- ${cur}))
;;
esac
}
complete -F _git_branch_completions git