Adding an Emoji Status to Terminal (ZSH)

laurieontech

Laurie

Posted on August 21, 2019

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!

💖 💪 🙅 🚩
laurieontech
Laurie

Posted on August 21, 2019

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related