DEV Community

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

Posted on

Adding an Emoji Status to Terminal (ZSH)

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


Enter fullscreen mode Exit fullscreen mode

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


Enter fullscreen mode Exit fullscreen mode

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


Enter fullscreen mode Exit fullscreen mode

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) “


Enter fullscreen mode Exit fullscreen mode

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}$  "


Enter fullscreen mode Exit fullscreen mode

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!

Top comments (13)

Collapse
 
fcfn profile image
Peter Timoshevsky

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

Collapse
 
tiguchi profile image
Thomas Werner

Awesome! Added random status emojis to my Bash prompt:

Terminal screenshot

Collapse
 
laurieontech profile image
Laurie

Yay!!! 🎉

Collapse
 
thepeoplesbourgeois profile image
Josh • Edited

You can use emoji in bash-it, too!

Collapse
 
andy profile image
Andy Zhao (he/him)

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

Collapse
 
eclecticcoding profile image
Chuck

OK going to try this.

Collapse
 
andrewbrooks profile image
Andrew Brooks 👨‍💻

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

Collapse
 
sukima profile image
Devin Weaver

For an example of this in Bash: github.com/sukima/dotfiles/blob/ma...

Collapse
 
laurieontech profile image
Laurie

Love the dates theming! So fun.

Collapse
 
vintharas profile image
Jaime GonzĂĄlez GarcĂ­a

❤️ Epic! 😁👍

Collapse
 
ben profile image
Ben Halpern

🤯😄🎉✅

Collapse
 
laurieontech profile image
Laurie

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

Collapse
 
lewixlabs profile image
Luigino De Togni

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