loading...
Cover image for Adding an Emoji Status to Terminal (ZSH)

Adding an Emoji Status to Terminal (ZSH)

laurieontech profile image Laurie ・2 min read

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 use vim 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 by:

laurieontech profile

Laurie

@laurieontech

Software dev at Gatsby | DC techie | Conference speaker | egghead Instructor | TC39 Educators Committee | Girls Who Code Facilitator | Board game geek | @laurieontech on twitter

Discussion

markdown guide
 

Thanks! BTW, I use the built-in fino theme that uses emojis to show if the git working tree is dirty or not.

 

You can use emoji in bash-it, too!

 

Awesome! Added random status emojis to my Bash prompt:

Terminal screenshot

 
 

Awesome!! Very excited to see this post out! 👏👏👏

 
 

Love some terminal candy! Setting this up asap, thanks for the detailed write-up. 👏👏

 
 

Haha, can we expect a screenshot of your updated terminal soon?!

 
 
 

Nice!
A little difference, in macos, default themes folder is here (hidden)
cd ~/.oh-my-zsh/themes