Last active
February 9, 2024 14:19
-
-
Save gilmoregrills/aac125323174a4dc767d01ba360c3d2c to your computer and use it in GitHub Desktop.
custom shell prompt
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
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