-
Notifications
You must be signed in to change notification settings - Fork 0
/
bash-completion
49 lines (37 loc) · 1.25 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
#/usr/bin/env bash
# shorthand for navigating to smog repos
goto() {
cd $( smog path "$1" )
}
_smog_complete() {
local cmd smog
local all_commands=(get add check list help version search)
local pkg_commands=(show path set sync update link unlink remove build upgrade)
all_commands+=(${pkg_commands[@]})
# -- complete command name -- #
if [ $COMP_CWORD -eq 1 ]; then
if [ -z "${COMP_WORDS[1]}" ]; then
COMPREPLY+=( "${all_commands[@]}" )
else
COMPREPLY+=( $( compgen -W "${all_commands[*]}" "${COMP_WORDS[1]}" ) )
fi
return
fi
# -- complete package name -- #
[ $COMP_CWORD -eq 2 ] || return
# check if command expects PKG as argument
for cmd in ${pkg_commands[@]}; do [ "$cmd" == "${COMP_WORDS[1]}" ] && break; done
[ "$cmd" == "${COMP_WORDS[1]}" ] || return
smog="${COMP_WORDS[0]}"
if [ -z "${COMP_WORDS[2]}" ]; then
COMPREPLY+=( $( $smog list ) )
else
COMPREPLY+=( $( compgen -W "$( $smog list )" "${COMP_WORDS[2]}" ) )
fi
}
_goto_complete() {
local smog=$(command -v smog) || return
COMPREPLY+=( $( compgen -W "$( $smog list )" "${COMP_WORDS[1]}" ) )
}
complete -F _smog_complete smog
complete -F _goto_complete goto