Tips and Tricks
Useful tools
- Homebrew
- Command-line fuzzy finder (fzf)
- Graphical user interface for Git (Git Cola)
- Power tools for kubectl (kubectx + kubens)
- The kubectx for operators.
Useful aliases
Kubectl
You will need kubectl
, kubectx
, kubens
for this aliases to work
k
instead of kubectlkc
instead of kubectl-ctxkn
instead of kubectl-ns
alias k=kubectl
alias kc=kubectl-ctx
alias kn=kubectl-ns
Custom prompt (PS1)
Update your .bashrc
file.
Example 1
- Custom colors
- Branch name info
PROMPT_COMMAND='__git_ps1 "${debian_chroot:+($debian_chroot)}\[\033[1;31m\]\u\[\033[1;36m\]@\[\033[01;32m\]\h\[\033[01;34m\]:/\W\[\033[00m\]" "\[\033[01;34m\]\$ \[\033[00m\]"'
Example 2
- Custom colors
- Virtual environment info
- Kubernetes current context info
- Branch name info
enablegitprompt() {
. ~/.git-prompt.sh
GIT_PS1_SHOWCOLORHINTS=true
GIT_PS1_SHOWDIRTYSTATE=true
GIT_PS1_SHOWUNTRACKEDFILES=true
GIT_PS1_SHOWUPSTREAM="auto"
GIT_PS1_VENV="\$(virtualenv_info)";
__k8s_cluster_prompt() {
if [[ $(pwd) == $HOME/<project_path>* ]];
then
echo "($(kubectl config get-contexts | tail -1 | awk '{print $2}')"
fi
}
__k8s_namespace_prompt() {
if [[ $(pwd) == $HOME/<project_path>* ]];
then
echo "/$(kubectl config get-contexts | tail -1 | awk '{print $5}'))"
fi
}
__venv_prompt() {
if [[ ! -z ${VIRTUAL_ENV} ]]; then
VENV_VAR=$(echo $VIRTUAL_ENV | sed 's/.*\///')
echo "($VENV_VAR) "
else
echo ""
fi
}
VENV_PROMPT="\$(__venv_prompt)"
K8S_CLUSTER_PROMPT="\$(__k8s_cluster_prompt)"
K8S_NAMESPACE_PROMPT="\$(__k8s_namespace_prompt)"
PROMPT_COMMAND='__git_ps1 "${VENV_PROMPT}${debian_chroot:+($debian_chroot)}\[\033[1;31m\]\u\[\033[1;36m\]@\[\033[01;32m\]\h\[\033[01;34m\]:/\W\[\033[00m\]" "${K8S_CLUSTER_PROMPT}${K8S_NAMESPACE_PROMPT}\\[\033[01;34m\]\$ \[\033[00m\]"'
}
enablegitprompt