-
Notifications
You must be signed in to change notification settings - Fork 1
/
completion.zsh.inc
64 lines (59 loc) · 2.03 KB
/
completion.zsh.inc
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
63
autoload -U +X bashcompinit && bashcompinit
zmodload -i zsh/parameter
if ! (( $+functions[compdef] )) ; then
autoload -U +X compinit && compinit
fi
_python_argcomplete() {
local prefix=
if [[ $COMP_LINE == 'gcloud '* ]]; then
if [[ $3 == ssh && $2 == *@* ]] ;then
# handle ssh user@instance specially
prefix=${2%@*}@
COMP_LINE=${COMP_LINE%$2}"${2#*@}"
elif [[ $2 == *'='* ]] ; then
# handle --flag=value
prefix=${2%=*}'='
COMP_LINE=${COMP_LINE%$2}${2/'='/' '}
fi
fi
local IFS=''
COMPREPLY=( $(IFS="$IFS" COMP_LINE="$COMP_LINE" COMP_POINT="$COMP_POINT" _ARGCOMPLETE_COMP_WORDBREAKS="$COMP_WORDBREAKS" _ARGCOMPLETE=1 "$1" 8>&1 9>&2 1>/dev/null 2>/dev/null) )
if [[ $? != 0 ]]; then
unset COMPREPLY
return
fi
# if one completion without a trailing space, add the space
if [[ ${#COMPREPLY[@]} == 1 && $COMPREPLY != *[=' '] ]]; then
COMPREPLY+=' '
fi
if [[ $prefix != '' ]]; then
typeset -i n
for ((n=0; n < ${#COMPREPLY[@]}; n++));do
COMPREPLY[$n]=$prefix${COMPREPLY[$n]}
done
fi
}
complete -o nospace -o default -F _python_argcomplete "gcloud"
_completer() {
command=$1
name=$2
eval '[[ -n "$'"${name}"'_COMMANDS" ]] || '"${name}"'_COMMANDS="$('"${command}"')"'
set -- $COMP_LINE
shift
while [[ $1 == -* ]]; do
shift
done
[[ -n "$2" ]] && return
grep -q "${name}\s*$" <<< $COMP_LINE &&
eval 'COMPREPLY=($'"${name}"'_COMMANDS)' &&
return
[[ "$COMP_LINE" == *" " ]] && return
[[ -n "$1" ]] &&
eval 'COMPREPLY=($(echo "$'"${name}"'_COMMANDS" | grep ^'"$1"'))'
}
unset bq_COMMANDS
_bq_completer() {
_completer "CLOUDSDK_COMPONENT_MANAGER_DISABLE_UPDATE_CHECK=1 bq help | grep '^[^ ][^ ]* ' | sed 's/ .*//'" bq
}
complete -o default -F _bq_completer bq
complete -o nospace -F _python_argcomplete gsutil