Mar 27, 2008

LINUX: Coloring your zsh shell in ubuntu

Some people will be bored looking at colorless terminal as i usually look. I do 50% of my laptop by using my terminal(CLI) on my Ubuntu 7.10 Gutsy Gibbon. I used to use bash shell a few weeks ago and bash do have some coloring on the shell, but still a lil bit boring.

But recently I change myself to zsh shell to do more shell programming. It's not the best shell for script/programming, but I get/read a lot of feedback from other linux user that this shell is suitable for shell scripting/programming.

So I this is simple tutorial on how to color your terminal to your need and make it a litle bit interesting to look at, so maybe you can spend more time to do you programming :P

First of all, you need to know the color code for shell, here is the list:
  • Choices : red, green, yellow, blue, magenta, cyan and white. The color codes for this are 30 (black), 31(red), 32 (green), 33 (yellow), 34 (blue), 35 ( magenta), 36 (cyan), 37 (white).
So now for coloring the zsh shell, you need to make a file name ".zshrc" on user's home folder. you can create the file by this command:
  • touch ~/.zshrc
After that, you need to do a litle coding to make your shell prompt. Open up your .zshrc that you just created by using any text editor of your choices. As for me, I prefer to use nano. So here is my command:
  • nano ~/.bashrc
This will open the .zshrc file inside your terminal, it is plain file without any text inside. So all you have to do is write the code. Here is some tips:
  • for prompt option you just need to add "PROMPT=" command inside .zshrc but if you would like to make some differences, you can try to do it on the right side by using this "RPROMPT="
  • here is some variable which will be recognized by shell: (%n)Username , (%B , %b)Bold text, (%~)Current Directory, (%U , %u)Underline, (%m)Machine name, (%h)Number of shell's history, (%t)Time and etc.
  • For coloring you have to use this %{\e[0;31m%} , and by changing number "31" you can change the color by the code given earlier.
  • So here is a simple example to create your prompt: paste this inside your .zshrc
    • PROMPT=$'%{\e[0;32m%}%UTell zsh what to do!%u %{\e[0m%}'
    • Save and exit.
    • Restart your terminal and you will see your prompt changing to :
      • Tell zsh what to do!
  • So you can try yourself to color up your terminal shell by writing your own .zshrc ~!
here is my screenshots:After applying the .zshrc in home folder

Thank you for your unbelievable support on Negative Zero - Permission to read and write blog for nearly 4 years. Don't forget to like Negative Zero on Facebook. Blog Directory

Post(s) you might like to read :

1 comment:

  1. Uhh, dude. "nano ~/.bashrc" is _not_ how you edit the .zshrc file. I think you meant "nano ~/.zshrc"