我遇到了 kubectl 别名完成的问题,当
kubectl
与 --kubeconfig
时,它不会通过 Tab 自动完成。
但是当我使用完整的 kubectl 命令(通过 control + option + e 扩展)时,它会起作用。
系统信息:
14.3.1
bash-completion@2
已安装本地设置:
$ type kk
kk is aliased to 'kubectl --kubeconfig ~/.kube/8/config'
$ complete -p kk
complete -o bashdefault -o default -o nosort -F __start_kubectl kk
$ cat ~/.inputrc
# allow iso-latin1 characters to be inserted
set convert-meta on
# don't strip characters to 7 bits when reading
set input-meta on
set completion-ignore-case on
set show-all-if-ambiguous on
set show-all-if-unmodified on
set mark-symlinked-directories on
set print-completions-horizontally on
set enable-bracketed-paste off
set colored-stats on
set skip-completed-text on
详情(视频中): https://streamable.com/poigy6
从 @Tblue 获取线索,别名补全工作通过 cykerway/complete-alias
得以完善步骤:
$ curl -o ~/.config/complete_alias -fsSL https://github.com/cykerway/complete-alias/raw/master/complete_alias
$ source ~/.config/complete_alias
# verify
$ type _complete_alias
$ alias kk='kubectl --kubeconfig ~/.kube/8/config'
$ complete -F _complete_alias kk
或在 rc 文件中:
alias k1='kubecolor --kubeconfig ~/.kube/1/config'
alias k2='kubecolor --kubeconfig ~/.kube/2/config'
alias k3='kubecolor --kubeconfig ~/.kube/2/config'
source ~/.config/complete_alias
complete -o nosort -o bashdefault -o default -F _complete_alias $(alias | sed -rn 's/^alias ([^=]+)=.+kubec.+$/\1/p' | xargs)