forked from rmm5t/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbash_completion
45 lines (40 loc) · 1.3 KB
/
bash_completion
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
35
36
37
38
39
40
41
42
43
44
45
# http://onrails.org/articles/2006/11/17/rake-command-completion-using-rake
if [ -f ~/bin/rake_completion ]; then
. ~/bin/rake_completion
fi
# Completion for custom git aliases
# Borrowed and modified from:
# https://github.com/bronson/dotfiles/blob/731bfd95/.bashrc#L81
complete -o bashdefault -o default -o nospace -F _git g 2>/dev/null \
|| complete -o default -o nospace -F _git g
__define_git_completion () {
eval "
_git_$2_shortcut () {
COMP_LINE=\"git $2\${COMP_LINE#$1}\"
let COMP_POINT+=$((4+${#2}-${#1}))
COMP_WORDS=(git $2 \"\${COMP_WORDS[@]:1}\")
let COMP_CWORD+=1
local cur words cword prev
_get_comp_words_by_ref -n =: cur words cword prev
_git_$2
}
"
}
__git_shortcut () {
type _git_$2_shortcut &>/dev/null || __define_git_completion $1 $2
# alias $1="git $2 $3"
# complete -o default -o nospace -F _git_$2_shortcut $1
complete -o bashdefault -o default -o nospace -F _git_$2_shortcut $1 2>/dev/null \
|| complete -o default -o nospace -F _git_$2_shortcut $1
}
__git_shortcut gco checkout
__git_shortcut gc commit
__git_shortcut gl pull
__git_shortcut glr pull
__git_shortcut gp push
__git_shortcut gs status
__git_shortcut gb branch
__git_shortcut gu branch
__git_shortcut gd diff
__git_shortcut gcp cherry-pick
__git_shortcut gr remote