Last active
July 25, 2018 01:55
-
-
Save stringsn88keys/cf7e805d3638ed621b034a7872882b83 to your computer and use it in GitHub Desktop.
.zlogin hooks to switch your config back from "production"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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