Common ZSHRC Extensions
When using oh-my-zsh, you can add some extensions and custom code to your .zshrc file to improve your workflow. Below are some common extensions that can be added to your .zshrc file.
Useful zsh plugins
- Add these to your
.zshrcfile:plugins=(git kubectl kube-ps1)
- Add these to your
-
- A utility to switch between Kubernetes contexts and namespaces easily. It provides a command-line interface to manage multiple Kubernetes clusters and namespaces efficiently.
Run
kubens namespace-nameto switch to the desired Kubernetes namespace. alias for kube context switching
- Add the following alias to your
.zshrcfile to switch between Kubernetes contexts easily:
alias kx="/opt/homebrew/bin/kubectx"Run
kx aks-cluster-nameto switch to the desired Kubernetes context.- Add the following alias to your
-
- A Zsh prompt extension that displays the current Kubernetes context and namespace in your terminal prompt. It helps you keep track of which cluster and namespace you are working with.
Master/main push sanity checks
- Add the following code to your
.zshrcfile to prevent accidental pushes to themasterormainbranches. This code will check if you are on themasterormainbranch and prompt you for confirmation before allowing the push.
- Add the following code to your
# Sanity Checks
preexec () {
if [[ ${1} =~ "gpush" || ${1} =~ "git push" ]];then
branch=$(git branch --show-current)
# Check if branch is main or master and stop push going straight through
if [[ ${branch} == "master" || ${branch} == "main" ]];then
read -q "execStatus?----- To master? Really? [y/n] ----- "
if [[ ${execStatus} == "y" ]];then
printf "\nExecuting...\n"
else
printf "\nCancelled $1... Refreshing shell.\n"
exec zsh
fi
fi
fi
}
- Automatically switch to main/master when you get the branch wrong
- Add the following code to your
.zshrcfile to automatically switch to themainormasterbranch if you try to checkout a non-existent branch.
- Add the following code to your
git() {
if [[ "$1" == "checkout" && "$#" -eq 2 ]]; then
case "$2" in
master)
command git checkout master || command git checkout main
;;
main)
command git checkout main || command git checkout master
;;
*)
command git "$@"
;;
esac
else
command git "$@"
fi
}
- Use functions to make switching azure account easier
- Add the following aliases to your
.zshrcfile to switch between Azure accounts easily:
- Add the following aliases to your
# Login automatically
function az_login_hmcts {
export AZURE_CONFIG_DIR=~/.azure
az login
}
# Prompt for device code so it doesn't use your default account
function az_login_crime_nonlive {
export AZURE_CONFIG_DIR=~/.azure-crime-nonlive
az login --use-device-code
}
# Prompt for device code so it doesn't use your default account
function az_login_crime_live {
export AZURE_CONFIG_DIR=~/.azure-crime-live
az login --use-device-code
}
This page was last reviewed on 2 September 2025.
It needs to be reviewed again on 2 September 2026
by the page owner platops-build-notices
.
This page was set to be reviewed before 2 September 2026
by the page owner platops-build-notices.
This might mean the content is out of date.


