Skip to content

Instantly share code, notes, and snippets.

@tyhawkins
Last active March 12, 2021 18:27
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 tyhawkins/7bcef6e280688e362dbdf9a1aba54a94 to your computer and use it in GitHub Desktop.
Save tyhawkins/7bcef6e280688e362dbdf9a1aba54a94 to your computer and use it in GitHub Desktop.
Shell environment snippets
# save as much history as possible
HISTFILE="$HOME/.zsh_history"
HISTSIZE=10000000
SAVEHIST=10000000
# zsh plugins
plugins=(
aws
docker
git
kubectl
kube-ps1
rsync
terraform
)
# kube-ps1 prompt
PROMPT=$PROMPT'$(kube_ps1) '
kubeoff
autoload -U compinit && compinit
export GPG_TTY=$(tty)
source $HOME/.aliases
if [ -z "$SSH_AUTH_SOCK" ] ; then
eval `ssh-agent -s`
ssh-add
fi
# my aliases
alias kctx='kubectx'
alias kns='kubens'
alias history='history -i'
alias tfaa='terraform apply --auto-approve'
## Add a timer and the time to the terminal
## replace gdate with date if running on a Linux system
# refreshes the prompt every $TMOUT seconds
TMOUT=15
function preexec() {
timer=$(($(gdate +%s%0N)/1000000))
}
function precmd() {
if [ $timer ]; then
now=$(($(gdate +%s%0N)/1000000))
calculated=$(( $now-$timer ))
hours=$(( $calculated/1000/3600 ))
min=$(( $calculated/1000/60 ))
sec=$(( ($calculated/1000)%60 ))
if [[ "${calculated}" -le 1000 ]]; then
elapsed="%F{magenta}${calculated}ms"
elif [[ "${calculated}" -le 60000 ]]; then
elapsed="%F{green}$(( ${calculated} / 1000 ))s"
else
if [ "$hours" -gt 0 ]; then
min="$(( $min%60 ))"
elapsed="%F{red}${hours}h${min}m${sec}s"
else
elapsed="%F{yellow}${min}m${sec}s"
fi
fi
export RPROMPT="[${elapsed}%f] [%F{green}%D{%Y/%m/%f}%f|%F{cyan}%T%f]"
unset timer
fi
}
function TRAPALRM() {
zle reset-prompt
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment