-
Notifications
You must be signed in to change notification settings - Fork 0
/
.zsh.completion
44 lines (38 loc) · 1.63 KB
/
.zsh.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
autoload -Uz bracketed-paste-magic
zle -N bracketed-paste bracketed-paste-magic
autoload -Uz compinit && compinit -i
autoload -Uz bashcompinit && bashcompinit -i
set functionzeroarg # $0 is set to the name of file containing function if function was sourced (Not the calling script)
set alwaystoend # Completion always matches to the end of the match
set nocompleteinword # Cursor is set to the end of the word if completion is started
export KC_COMPLETION_FILE="$HOME/.zsh/completions.d/kubectl.sh"
fpath=(.zsh/completions.d $fpath)
autoload -Uz url-quote-magic
zle -N self-insert url-quote-magic
# Put in a test here for if the file is locked and loop until a) it unlocks or
# b) we timeout after 20 seconds.
if [[ ! -f "${KC_COMPLETION_FILE}" ]]; then
echo "Generating kubectl completion file '${KC_COMPLETION_FILE}'"
. "${HOME}/.zsh/completions.d/kubectl-functions.sh"
generate_kc_completion_if_needed
fi
if [[ -f "${KC_COMPLETION_FILE}" ]]; then
2>/dev/null zsystem flock -f lockvar -t 20 ${KC_COMPLETION_FILE} && \
source ${KC_COMPLETION_FILE} && \
zsystem flock -u $lockvar
export KC_EXPANDED="True"
else
echo "Could not source in the kubectl completion file '${KC_COMPLETION_FILE}'"
echo "We likely just ran 'generate_kc_completion_if_needed' so you'll need to"
echo "figure out why we could not and and correct the issue."
export KC_EXPANDED="False"
fi
alias kc='kubectl'
kcshell() {
args=$(echo "$@" | sed -e 's/describe pod //')
kubectl exec --stdin --tty ${=args} -- /bin/bash
}
complete -F _kubectl kc
complete -F _kubectl kcshell
complete -F _kubectl show-cluster-pods
complete -F _kubectl show-cluster-nodes