Bash Command Prompt Flair on a Mac

A couple of months ago I was going through Apple’s Introduction to Swift, wherein they mentioned that Swift’s support of unicode allowed that you could use emoji as variable names. They were quick to point out that it was a bad practice, and you shouldn’t do it, but it was kind of fun. More recently, I was in my terminal and I wondered if there was something cool I could do to make my command prompt a little more interesting. I started out utilizing a character that Apple had put in it’s character set: A simple black Apple logo. But then, remembering the Swift book, I wondered if I could do the same thing with Emoji.

The Bash shell is the interface you see when you open up your terminal. It’s a common tool, and while other people enjoy other shells, I’m quite happy with Bash. Bash allows you to make adjustments to it through some simple files that are run on startup, and a useful scripting language. The file to make adjustments to is the .bash_profile file and it lives if your home directory. It’s a hidden file (due to the . at the beginning) and if you’ve never done anything with it, you might not even have one. That’s okay, you can make one.

I started out this adventure seeing if I could get the Apple in my terminal. So I did a quick google search and learned that you can set what your prompt looks like by using the PS1 variable. In that you can set a few items that will be expanded:

export PS1="\w \u

The above, when applied to a terminal, will yield:

~/Development aeiche

Specifically, my location and username.

The result was a little underwhelming.

That’s when I decided to open up the emoji keyboard and see if I could put something else in there.

The trick is to copy the Character Info by right clicking on the Emoji you want. You can then paste it wherever you want. When you paste it you’ll get the character code and description, which you can delete. Then put it in your variable.

 

I added a couple of spaces after the character to make things a bit easier to read. As a result, whenever I open a terminal this greets me:

Is is kind of silly? Absolutely, but I still get a kick out of it.

Add Comment

Required fields are marked *. Your email address will not be published.