Switch From Bash to Zsh

Have used bash for 6+ years, I finally decided to switch to zsh. This is not my first time trying zsh tho, last time I tried zsh I believe oh-my-zsh is not out or very popular yet, somehow zsh seems doesn’t impressive me a lot. Probably at that time I still feel strong tied to bash somehow, habit, workflow, autocompletion style etc.

Yesterday I tried to give zsh one more chance, thanks to oh-my-zsh and peepcode, this time the exprience is much more better than last time, I managed to reuse most of my bash configuration when I can try the new features of zsh, which is pretty good for my transition and the habit I already get used to in bash in the past.

[Shell Prompt]
Zsh users love to share their prompt, to follow their tradition, I’m going to do that here as well, below is my Zsh prompt screenshot:

zsh prompt

The idea is mostly inspired from topfunky’s zsh-simple, except that I used the dark background and customized some of the colors.

Below is the configuration section in ~/.zshrc:

# Colors
autoload -U colors
colors
setopt prompt_subst

# Prompt
local smiley="%(?,%{$fg[green]%}☺%{$reset_color%},%{$fg[red]%}☹%{$reset_color%})"

PROMPT='
%{$fg[blue]%}%~%{$reset_color%}
${smiley} %{$reset_color%}'


RPROMPT='%{$fg_bold[grey]%} $(~/.rvm/bin/rvm-prompt)$(~/bin/git-cwd-info)%{$reset_color%}'

[oh-my-zsh]
To reuse bash configurations and make your transition more smooth and enjoyable, oh-my-zsh is highly recommended. I used the manual way to install it, cuz I need to make some customizations about the default installation configurations.

$ git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh
$ cp ~/.zshrc ~/.zshrc.orig
$ cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc

Instead of making zsh the default shell of my system, I started zsh in ~/.bashrc

. ~/bin/dotfiles/bash/env
. ~/bin/dotfiles/bash/config
. ~/bin/dotfiles/bash/completions
. ~/bin/dotfiles/bash/aliases
. ~/bin/dotfiles/bash/autojump

# start zsh
zsh

The reason to start a new zsh process instead of “exec zsh -l” is I could still fall back to bash by just typing “exit” when needed, pretty convenient.

Customized the oh-my-zsh .zshrc file and append my previous zsh configuration to it after installation.

$ cat ~/.zshrc.orig >> ~/.zshrc

[oh-my-zsh plugins]
oh-my-zsh has plenty of built-in plugins available for your daily usage, below is a list of plugins that I’m evaluating:

plugins=(git rails3 ruby osx brew rvm cp gem bundler coffee)

[RVM]
I use RVM, below command is needed in ~/.zshrc

# RVM
if [[ -s ~/.rvm/scripts/rvm ]] ; then source ~/.rvm/scripts/rvm ; fi

[History Search]
I’d like to use upper arrow and down arrow to search the shell history which matches my current typed word, below is the needed configuration for zsh since it doesn’t use readline (~/.inputrc) as bash does. oh-my-zsh has a slightly different configuration but I like mine below more cuz that’s what I already get used to in my bash configruation before.

bindkey  '^[[A'  history-beginning-search-backward
bindkey  '^[[B'  history-beginning-search-forward

[Bash History Migration]
Speaking of history search, it’s better if we can reuse the bash history I had before, fortunately it’s not a hard job with the help of google. Seems someone already did this before, I just stole their solution which works perfectly for me.

$ cat ~/.bash_history | bash-history-to-zsh-history > /tmp/zsh_history
$ cat ~/.zsh_history >> /tmp/zsh_history
$ mv /tmp/zsh_history ~/.zsh_history

[Conclusion]
As people always say “just do it”, probably so far the conclusion for zsh for me is “just use it”

历史上的今天:

Related posts:

Trackbacks for this post

  1. Bash like history search functionality for Zsh | Samson's Weblog United States WordPress Unknow Os

Got something to say? Go for it!

使用新浪微博登陆