Power yourself with zsh and iTerm2
Shells supported by Mac/Linux
No matter in macOS or Linux, the default shell is bash. However, we have many shells to choose from in macOS/Linux, e.g. zsh, csh, etc. You can take a look at /etc/shells to check the supported shells:
You can check your default shell using this command:
echo $SHELL
Why zsh
Many mac users are in favor of zsh. To me, there are several advantages compared to bash:
- more intelligent command recommendations. No matter whether you want to try some shell commands or jump into some specific folders,
tab
key is all you need. - More fancy themes you can choose for zsh
- zsh can display the git branch name if the directory is a git repo
macOS Setup
iTerm2
I would like to recommend using iTerms (https://iterm2.com/). Lots of amazing features in iTerms can make you more efficient.
Oh My Zsh
Although macOS already has its zsh, I still recommend using Oh My Zsh (https://ohmyz.sh/#install, https://github.com/ohmyzsh/ohmyzsh). A simple script to install it:
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
Now the shell will be switched to zsh. Same as the previous bash config file ~/.bashrc
, the config file of zsh is now ~/.zshrc
.
To be noted here, after installing Oh My Zsh on Mac, your system will generate a new .zshrc
file. There are two scenarios here:
- If you are using default zsh, the contents of your old
.zshrc
file will all move to.zshrc-pre-oh-my-zsh
. Therefore, if you have some customized configurations, it is better to copy them from.zshrc-pre-oh-my-zsh
into.zshrc
- If you are using bash, you can also copy your customize configurations from
.bashrc
or.bash_profile
into.zshrc
. Or you can simply put the following commands into.zshrc
:
source ~/.zshrc
source ~/.bash_profile
zsh theme
Inside ~/.zshrc
, you can set up zsh theme using the following command:
ZSH_THEME="robbyrussell"
You can find out all themes of Oh My Zsh in ~/.oh-my-zsh/themes
. In addition, you can also check the detailed info of all themes in Oh My Zsh Themes.
For me, I made some changes to the theme agnoster
:
The first one is the conda/pyenv virtual environment, the followings are hostname, directory, and git branch. The modified theme file is here, named as agnoster-custom.zsh-theme
. After downloading the file, you can put it into ~/.oh-my-zsh/custom/themes
, and change the setting in ~/.zshrc
:
ZSH_THEME="agnoster-custom"
You can also change the themes based on your preference, by following the zsh grammars here.
Remember to run source ~/.zshrc
to activate your changes
Powerline Setup
Powerline is a status line plugin for vim, and provides status lines and prompts for several other applications, including zsh, bash, tmux, IPython, Awesome, i3, and Qtile. (reference from powerline)
The entire setup is as follows:
- You can simply install the powerline by using pip:
pip install --user powerline-status
--user
ensures that powerline is installed into ~/.local
, which makes it easy for you to manage it.
2. Run the following commands to install powerline fonts:
git clone https://github.com/powerline/fonts.git
cd fonts
./install.sh
3. You also need to add the following into ~/.zshrc
to enable zsh to use powerline fonts:
export PATH=$HOME/.local/bin:$PATH
. ~/.local/lib/python3.7/site-packages/powerline/bindings/bash/powerline.sh
After running source ~/.zshrc
, some weird thing happens:
This is because you haven’t setup iTerm2’s font:
Try to search for the fonts ending with Powerline
.
Then everything is finished, you can go ahead with your new ZSH now!