-
Notifications
You must be signed in to change notification settings - Fork 14
/
bash_completion
62 lines (60 loc) · 1.41 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
_umpf_completion()
{
local cmd _umpf_cmd
local -a completion_opts completion_cmds
_umpf_cmd="${COMP_WORDS[0]}"
completion_opts=( $(_parse_help umpf) )
completion_cmds=( $("${_umpf_cmd}" --help | sed -n 's/^ \([^ -][^ ]*\) .*$/\1/p') )
_init_completion -s || return
case "${prev}" in
--patchdir|-p)
_filedir -d
return 0
;;
--remote|-r)
COMPREPLY+=($( compgen -W "$(git remote) refs/heads" -- $cur ) )
return 0
;;
*)
;;
esac
for (( i=1 ; i<${cword}; i++ )); do
local tmp="${words[i]}"
case "${tmp}" in
-p|-r)
i=$[i+1]
;;
-*)
;;
*)
cmd="${tmp}"
;;
esac
done
case ${cmd} in
"")
COMPREPLY=( $( compgen -W "${completion_cmds[*]} help" -- $cur ) )
;;
diff|show|tag|tig|build)
local -a refs
refs=( $( compgen -W "$( git for-each-ref --format='%(refname:short)' refs/tags refs/heads refs/remotes)" -- $cur ) )
if [ ${#refs[@]} -eq 0 ]; then
COMPREPLY=( $( compgen -f -- $cur ) )
compopt -o filenames
else
COMPREPLY=( "${refs[@]}" )
fi
;;
merge)
COMPREPLY=( $( compgen -W "$( git for-each-ref --format='%(refname:short)' refs/heads refs/remotes)" -- $cur ) )
;;
format-patch)
COMPREPLY=( $( compgen -W "$( git for-each-ref --format='%(refname:short)' refs/tags)" -- $cur ) )
;;
esac
COMPREPLY+=( $( compgen -W "${completion_opts[*]}" -- $cur ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
return 0
} &&
complete -F _umpf_completion umpf