Skip to content

Instantly share code, notes, and snippets.

@gilmoregrills
Last active February 9, 2024 14:19
Show Gist options
  • Save gilmoregrills/aac125323174a4dc767d01ba360c3d2c to your computer and use it in GitHub Desktop.
Save gilmoregrills/aac125323174a4dc767d01ba360c3d2c to your computer and use it in GitHub Desktop.
custom shell prompt
autoload -Uz vcs_info
autoload -U colors && colors
SUCCESS_EMOJIS=("πŸ™†β€β™€οΈ" "πŸ’β€β™€οΈ" "πŸ™‹β€β™€οΈ")
FAILURE_EMOJIS=("πŸ™…β€β™€οΈ" "πŸ€¦β€β™€οΈ" "πŸ€·β€β™€οΈ")
setopt prompt_subst
setopt PROMPT_SUBST
zstyle ':vcs_info:git:*' check_for_changes true
zstyle ':vcs_info:git:*' check_for_staged_changes true
zstyle ':vcs_info:git:*' formats ":%s(%b)"
precmd() {
myprompt
}
function myprompt() {
RETVAL=$?
vcs_info
local 'STATUS_COLOR' 'PROMPTMOJI'
if [[ $RETVAL -eq 0 ]]; then
STATUS_COLOR=green
SIZE=${#SUCCESS_EMOJIS[@]}
INDEX=$(($RANDOM % $SIZE))
PROMPTMOJI="${SUCCESS_EMOJIS[$INDEX + 1]}"
else
STATUS_COLOR=red
SIZE=${#FAILURE_EMOJIS[@]}
INDEX=$(($RANDOM % $SIZE))
PROMPTMOJI="${FAILURE_EMOJIS[$INDEX + 1]}"
fi
if [ $FASTPROMPT ]; then
PS1=%F{blue}%~' '"πŸƒβ€β™€οΈ"$'\n'%F{$STATUS_COLOR}'↳ '%f
return
fi
local 'TF_VERSION_PROMPT'
if [ -e .terraform-version ]; then
TF_VERSION_PROMPT="using %F{magenta}tf$(tfenv version-name)%f "
else
TF_VERSION_PROMPT=""
fi
local 'AWS_PROMPT'
if [ -z $AWS_PROFILE ]; then
AWS_PROMPT=""
else
AWS_PROMPT="on %F{yellow}$AWS_PROFILE%f "
fi
if kubectl config current-context &> /dev/null ; then
KUBE_CONTEXT_PROMPT="on %F{cyan}$(kubectl config current-context)($(kubens -c))%f "
else
KUBE_CONTEXT_PROMPT=""
fi
PS1=%F{blue}%~%f%F{green}${vcs_info_msg_0_}%f' '"$AWS_PROMPT""$TF_VERSION_PROMPT""$KUBE_CONTEXT_PROMPT""$PROMPTMOJI"$'\n'%F{$STATUS_COLOR}'↳ '%f
# PS0=$'\nps0'
# PS2="ps2 > "
return
}
alias fastprompt="export FASTPROMPT=true"
alias slowprompt="unset FASTPROMPT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment