Skip to content

Instantly share code, notes, and snippets.

@stringsn88keys
Last active July 25, 2018 01:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stringsn88keys/cf7e805d3638ed621b034a7872882b83 to your computer and use it in GitHub Desktop.
Save stringsn88keys/cf7e805d3638ed621b034a7872882b83 to your computer and use it in GitHub Desktop.
.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