How to zsh — without oh-my-zsh (Part 1, prompt colors)

Daniel Peach
4 min readOct 22, 2019

If you are here, hopefully you are looking for the same thing I was, and still am. You want a way to configure your own zsh, without pulling in a huge framework just to make small changes. oh-my-zsh is more than the de-facto tool to configure zshell. To many people it is the only way to do it. If you spend any time googling how to configure zsh, the first line in most tutorials is “ok, so we will start by installing a free framework called oh-my-zsh…”

But wait. I just want to change my prompt from myComputer% to something more legible. Oh and maybe use some syntactic colors, and if I could, show some git info? That’s all I want, and I want it to be mine. I don’t just want to install Joe Shmoe’s fancy open-source theme. (I am sure Joe is a great guy and put a lot of work into that theme, but I want to do it myself and learn a thing or two). Maybe down the road I could set up my own functions too. But the key here is you want to do it yourself, and you want to know exactly how and what is configuring your terminal you spend so much time in. So where to go from here?

Well, perhaps you came from bash world like me, and were also rudely thrown into the zsh world by Apple’s decision to change their default shell to zsh (just kidding Apple, I love you). If that is the case, you’ll hopefully be familiar with .bash_profile, .bashrc, or any of the other common config files. Well zsh has one too. It’s .zshrc, and it’s a pleasure to config in. Let’s start with the prompt.

You most likely will need to create your .zshrc file, so do so with

touch ~/.zshrc

Now, open zshrc with the editor of your choice. We will begin with the prompt. We will begin with something like PROMPT='Dan'. Dan is my name, use your own please… or use mine, I guess I don’t care you weirdo you. Anyways, a thing to note here: I am using single quotes. With zsh, single quotes are not always necessary, but with most things even slightly complex, they are, so a good practice is to always use single quotes for something like this.

Ok well you want your prompt to say more than just your name don’t you? Perhaps you are familiar with bash’s \h, \u, \w, etc macros to get your username, current machine, current directory, or whatever. Well no surprise, zsh has their own version. With zsh, you’ll use % instead of \. Checkout the full list of zsh prompt expansions here: http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html

Ok well for me, I used

PROMPT='%n in %~ -> '

This gives me who I am and where I am on the computer. So logged in as danDude and on my desktop, my prompt would look something like

Not very exciting, so let’s add some color. Again, this is very easy with zsh. No more of that tput setaf 124crap, now we just need zsh’s %F (for Foreground) and a color code. You can also use these built in colors from zsh’s Wiki, or try any of the color codes below:

I ended up

PROMPT='%F{208}%n%f in %F{226}%~%f -> '

You’ll see the %F (start foreground format) and %f (end foreground format. See http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html#Visual-effects for more visual effects options. I like to use bold as well. And awesome, we have color!

Your final .zshrc should look something like

This is just the beginning. In the next session we will look at how to get git (or other vcs) info in our prompt, and even how to push it to the other side. We will end up with something like this

See you there!

--

--