Last Updated: November 19, 2020
·
73.8K
· itseranga

Customize terminal with oh-my-zsh

My terminal

  • Following is my customized terminal, it displays
  1. Current working directory
  2. Git branch name(when you in git repository)
  3. Battery charger indicator
  4. Customized line spaces

etc..

Picture

  • Before gonna implementation details of this terminal, I'l give brief introduction about some UNIX terms

What is shell

  • Shell is a software interface to the operating system

  • it interpret commands and acts as an intermediary between the user and the inner workings of the operating system

  • In OS-X environment default shell is bash

  • bash and zsh are some available shells

ZSH

  • zsh is on of UNIX command interpreter (shell).

  • The main features of zsh is the true auto tab completion and autocorrect(which not provide by bash)

  • In order to change you shell in OS-X environment, do following steps

  1. Go to system preference
  2. Select Users and Groups
  3. Right click your user account and select advance options(In order to make changes you have to unlock the panel by clicking lock icon in bottom)
  4. Change the login shell to /bin/zsh
  • You can define your zsh configurations in ~/.zshrc file

More info about zsh shell
http://www.slideshare.net/jaguardesignstudio/why-zsh-is-cooler-than-your-shell-16194692

OH-MY-ZSH

  • Simply OH MY ZSHELL!

  • It is a framework for managing zsh configuration

More info about oh-my-zsh
https://github.com/robbyrussell/oh-my-zsh

Install oh-my-zsh

  • According to the README, you can do curl to install oh-my-zsh
curl -L http://install.ohmyz.sh | sh
  • This command install oh-my-zsh in to you home directory ~/.oh-my-zsh/

  • It contains several important directories

  1. templates - contains template of a zshrc file(zshrc.zsh-template)
  2. themes - this is the place where we need to put our custom oh-my-zsh theme(this themes use to customize our terminal)

Creating custom theme

  • First need to define the name of the custom theme in ~/.zshrc file.

  • I have defined my theme as senzshell

Picture

Display battery indicator

green = '\033[01;32m'
red = '\033[01;31m'
yello = '\033[01;33m'
reset = '\033[00m'

color_out = (
    green if len(filled) > 6
    else yello if len(filled) > 4
    else red
)

out = color_out + out + reset
function battery_charge() {
    if [ -e ~/Workspace/dev-notes/oh-my-zsh/battery_indicator.py ]
    then
        echo `python ~/Workspace/dev-notes/oh-my-zsh/battery_indicator.py`
    else
        echo ''
    fi
} 

** Please note that, I'm using iTerm terminal with Smyck color theme**

Related protips:

git checkout remote branch

3 Responses
Add your response

Excellent article. it made my life easy!
thanks!!!

over 1 year ago ·

great read, check out my theme https://gist.github.com/encodes/5575420 and take a read of my https://coderwall.com/p/1y_j0q?i=1&p=1&q=author%3Aencodes&t%5B%5D=encodes < it covers a few things you may or may not know ;)

over 1 year ago ·

Thanks for your information :)

over 1 year ago ·