Skip to content

Instantly share code, notes, and snippets.

@tubaterry
Last active November 30, 2021 03:49
Show Gist options
  • Save tubaterry/d09c7bbd8000750fcce4e9f943e55eca to your computer and use it in GitHub Desktop.
Save tubaterry/d09c7bbd8000750fcce4e9f943e55eca to your computer and use it in GitHub Desktop.
ZSH prompt with finger guns πŸ‘‰ 😎 πŸ‘‰ (requires emoji support)
# Don't forget to set COMPLETION_WAITING_DOTS=false in your .zshrc - it doesn't always play nice with multiline prompts
# Troubleshooting breadcrumbs:
# Prompt design: http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html#Prompt-Expansion
# Zsh Line Editor (zle): http://zsh.sourceforge.net/Doc/Release/Zsh-Line-Editor.html
#Broken down into its component pieces because I was tired of looking at a nearly incomprehensible string
FG_USER_BADGE=$'%{$fg_bold[green]%}%n@%m%{$reset_color%}'
FG_TIMESTAMP=$'%{$fg[blue]%}%D{[%X]}%{$reset_color%}'
FG_CWD_DISPLAY=$'%{$fg[white]%}[%~]%{$reset_color%}'
FG_SHELL_DISPLAY=$'%{$fg_bold[blue]%}%#%{$reset_color%}'
#We use the %G to 'glitch' zsh into forcing the string to take up 3 character widths %{string%3G%}
FG_GUNS_WAITING=$'%(?.%{πŸ‘†πŸ˜ŽπŸ‘†%3G%}.%{πŸ‘ŽπŸ˜ πŸ‘Ž%3G%})'
FG_GUNS_FIRED=$'%(?.%{πŸ‘‰πŸ˜ŽπŸ‘‰%3G%}.%{πŸ‘ŽπŸ˜ πŸ‘Ž%3G%})'
FG_GUNS_DISPLAY=$FG_GUNS_WAITING
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[green]%}["
ZSH_THEME_GIT_PROMPT_SUFFIX="]%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DIRTY=" %{$fg[red]%}*%{$fg[green]%}"
ZSH_THEME_GIT_PROMPT_CLEAN=""
#Setup prompt lol
function βš’βŒ¨οΈ () {
PROMPT=$''"$FG_USER_BADGE $FG_TIMESTAMP $FG_CWD_DISPLAY"' $(git_prompt_info)
'"$FG_GUNS_DISPLAY $FG_SHELL_DISPLAY "
}
function πŸ‘†πŸ”«πŸ’₯πŸ’₯ () {
# Shoot them finger guns
FG_GUNS_DISPLAY=$FG_GUNS_FIRED
zle accept-line
βš’βŒ¨οΈ
# Reload em
zle reset-prompt
FG_GUNS_DISPLAY=$FG_GUNS_WAITING
βš’βŒ¨οΈ
# I've got some things in this file like a $TIMESTAMP and $SHORTRAND so i always have
# Easy access to make a unique filename or temp folder or whatevs.
if [ -f ~/.oh-my-zsh/custom/handy-vars.zsh ]; then
source ~/.oh-my-zsh/custom/handy-vars.zsh
fi
}
PROMPT=""
βš’βŒ¨οΈ
zle -N πŸ‘†πŸ”«πŸ’₯πŸ’₯
bindkey '^M' πŸ‘†πŸ”«πŸ’₯πŸ’₯
@tubaterry
Copy link
Author

@ejheil i think I had something else interfering earlier cuz i had the same behavior once i switched to a new machine. got it updated so it behaves better now, sorry it took so long to get back to you!

un-executed prompt, $? is 0: guns up (let's do this)
executed prompt, $? is 0: cool guy finger guns
$? is non-zero: angry thumbs down (i decided i didn't want that one to change so i don't erase the visual cue for a previously-failed command)

@ejheil
Copy link

ejheil commented Jan 14, 2020

Works great now, thanks!

@tubaterry
Copy link
Author

tubaterry commented Sep 29, 2020

Today's update: 'refactor' the variable names so I don't do dingus stuff like overwriting something as heavily used as $USER.
All the internal variables are now prefixed with FG_ and USER in particular is now FG_USER_BADGE.

Hooray for scoping.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment