Adding an Emoji Status to Terminal (ZSH)
Laurie
Posted on August 21, 2019
This post is inspired and credited in large part to @yechielk. He posted this tweet last night and I, like everyone else, also wanted to add emojis that reacted to the success of my commands!
This guide can likely be adapted for other setups, but in this case I'm running zsh
, specifically oh-my-zsh
so the instructions are based on that.
1 - Navigate to themes folder
oh-my-zsh
uses themes to define the visual display of the terminal window. So we'll start by navigating to the folder where the themes are.
cd ~/oh-my-zsh/themes
2 - Figure out what theme you're running
There are a ton of themes in that folder, but we only want to edit the one we're running. So let's find out what that is.
echo $ZSH_THEME
3 - Navigate into that theme file
I'm running alanpeabody
which I've customized over the years. So let's open that file.
Yes, I use
nano
! It works for me. You can usevim
or whatever else works for you.
nano alanpeabody.zsh-theme
4 - Create a variable that will set the emoji
This is the heart of what we're doing and I didn't write it. I lifted it from @yechielk dotfiles and made some modifications. Work smarter, not harder folks!
Note that you can replace these faces with whatever emoji, or even text, that you want.
local emoji="${debian_chroot:+($debian_chroot)}\$(if [ \$? == 0 ]; then echo 😊$; else echo 😓; fi) “
5 - Add variable to prompt
The final step is to find where in the theme your prompt is declared. Mine was at the bottom of the file and appropriately named PROMPT
. Prepend the definition with the emoji variable using the appropriate syntax and we're off to the races.
PROMPT="${emoji}${user} ${pwd}$ "
Note that spaces in this string are taken into account. I have one at the end so my typed commands are spaced out from my prompt, but I removed the one between emoji and my user since it takes up unnecessary space beyond the emoji visual buffer.
Complete!
And that's it. Remember to restart your terminal so that these changes can take effect. Have fun!
Posted on August 21, 2019
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.