Customize terminal with oh-my-zsh
My terminal
- Following is my customized terminal, it displays
- Current working directory
- Git branch name(when you in git repository)
- Battery charger indicator
- Customized line spaces
etc..
- 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
andzsh
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
- Go to system preference
- Select Users and Groups
- 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)
- 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 installoh-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
- templates - contains template of a
zshrc
file(zshrc.zsh-template
) - 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
You can find my
~/.zshrc
configuration file from github
https://github.com/erangaeb/dotfiles/blob/master/zshrcThen I have created a theme file
~/.oh-my-zsh/themes/senzshell.zsh-theme
(My custom terminal configurations setting define in this theme file)Theme file should have
.zsh-theme
extentionI have uploaded my theme file into github
https://github.com/erangaeb/dev-notes/blob/master/oh-my-zsh/senzshell.zsh-theme
Display battery indicator
I have used python script
battery_indicator.py
to display my laptop battery statusFound this script from
http://stevelosh.com/blog/2010/02/my-extravagant-zsh-prompt/#my-right-prompt-battery-capacityI have modified it to work with different terminal colors. Following is the modification that I have done
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
You can find the complete
battery_indicator.py
file from my github
https://github.com/erangaeb/dev-notes/blob/master/oh-my-zsh/battery_indicator.pyThen I have added
battery_charger
function to my custom themeIn my scenario I have put this file into
~/Workspace/dev-notes/oh-my-zsh/battery_indicator.py
(Change yourbattery_indicator.py
file path appropriately)
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:
Written by eranga bandara
Related protips
3 Responses
Excellent article. it made my life easy!
thanks!!!
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 ;)
Thanks for your information :)