Skip to content

Instantly share code, notes, and snippets.

@stringsn88keys
Last active Jul 25, 2018
Embed
What would you like to do?
.zlogin hooks to switch your config back from "production"
function safety_preexec() {
# Store the command that we're running.
CMD_NAME="$1"
}
function safety_precmd() {
if [[ "$CMD_NAME" =~ 'kubectl config use-context whatever-your-prod-is' ]]; then
PROD_TIME=$(date +%s)
CMD_NAME=""
fi
if ! [[ -z "$PROD_TIME" ]]; then
CURRENT_TIME=$(date +%s)
PROD_ELAPSED_TIME=$(($CURRENT_TIME - $PROD_TIME))
PROD_TIME_THRESHOLD=15
if [[ $PROD_ELAPSED_TIME -gt $PROD_TIME_THRESHOLD ]]; then
kubectl config use-context whatever-your-dev-is
PROD_TIME=""
fi
fi
}
[[ -z $preexec_functions ]] && preexec_functions=()
preexec_functions=($preexec_functions safety_preexec)
[[ -z $precmd_functions ]] && precmd_functions=()
precmd_functions=($precmd_functions safety_precmd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment