Oh my zsh and my custom prompt

Why?

On the one side, this is not really a development topic. It is about tools. Or, specifically, about command prompt in you favorite shell.

This is one of topics that is never asked on any interview, but still quite important for every developer. Because terminal and command line is what you deal with every day in your developer life.

So, let’s start from the classical default bash prompt on OSX, that looks quite ugly.

It shows you your current computer name, folder you are currently working in and your username. So far, so good. But just to get understanding on how can you improve it, here is my customized oh my zsh prompt.

Screen Shot 2016-04-27 at 23.02.16

What?

So, what is the real difference between default OSX prompt and customized one?

First of all, it shows you much more information than the default prompt. It shows you full directory path, checks the last return code of operation and even shows you if this directory is under git control, and git branch in that case. This information is highly customizable for your needs, and you can add there only what is really needed. In my specific case, I need full path to folder (to get the fully understanding where I am now all the time), and computer name (because it is common for me to work using ssh on completely different machine, and I need to see clearly where I am. And of course, see on what branch are you currently developing is useful for every developer.

Now, about colors. Many of us are still using terminal the same way it was used 30 years ago, but actually the progress is here with us and one can use the full color scheme in his/her terminal. So, why not? Colors can really help you to concentrate only on the information you need. For example, green arrow can show you that the last command was finished successfully, and red error shows you that there was error.

And, last but not least, I prefer two-liner. When the prompt is one line long, and you are trying to fix all the information you need there, you basically don’t have place for work.

How

There are many ways to implement these functionality, but we will do it the easiest way. I think, easiest and the most popular way is oh my zsh framework.

http://github.com/robbyrussell/oh-my-zsh

Basically, it is collection of various functionalities over zsh. Of course, one can implement it on his own even in bash, but it will probably take a lot of time from you. In oh my zsh you can go to the themes folder and create a new entry there. Of course, you can also modify (or even reuse if you don’t need customization) any existing theme. But I found at least one problem with update – all oh my zsh files are under git control, and that is how it does update – simple by git pull mechanism. So, this modified file will prevent your whole framework from updating.

Here is my customized oh my zsh scheme.

I, as an enterprise software developer, tried to isolate (mostly for readability) different parts of prompt, so that even inexperienced person can easily understand how is it combined.

So, the file itself it quite self describable. Please use and modify it =)

Leave a Reply

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