The following is a basic bash/zsh
setup to work with kubectl
+ nano
editor. It does the following:
- first it sets up autocompletion of both
kubectl
andk
. - it then proceeds to setup
nano
, first by changing the defaultkubectl
edit editor to it, then by enabling yaml syntax highlighting for the nano editor. - Lastly it sets up the
kn
alias to easily set the namespace wanted.
Bash version:
echo 'source <(kubectl completion bash)' >>~/.bashrc &&
echo 'alias k=kubectl' >>~/.bashrc &&
echo 'complete -o default -F \_\_start_kubectl k' >>~/.bashrc &&
echo 'KUBE_EDITOR="nano"' >>~/.bashrc &&
echo "alias kn='f() { [ \"\$1\" ] && kubectl config set-context --current --namespace $1 || kubectl config view --minify | grep namespace | cut -d\" \" -f6 ; } ; f'" >>~/.bashrc &&
source ~/.bashrc &&
git clone https://github.com/LorenzoScebba/nano-highlight.git &&
echo 'include "~/nano-highlight/yaml.nanorc"' >>~/.nanorc &&
echo 'set tabsize 2' >>~/.nanorc
zsh version:
echo 'alias k="kubectl"' >>~/.zshrc &&
sed -i.bak -E 's|plugins=\((.*)\)|plugins=\(\1 kubectl\)|g' ~/.zshrc &&
echo "alias kn='f() { [ \"\$1\" ] && kubectl config set-context --current --namespace $1 || kubectl config view --minify | grep namespace | cut -d\" \" -f6 ; } ; f'" >>~/.zshrc &&
source ~/.zshrc &&
git clone https://github.com/LorenzoScebba/nano-highlight.git &&
echo 'include "~/nano-highlight/yaml.nanorc"' >>~/.nanorc &&
echo 'set tabsize 2' >>~/.nanorc