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: [cc lang=”bash” nowrap=”false”] # 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%}’ [/cc] [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. [cc lang=”bash” nowrap=”false”] $ 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 [/cc] Instead of making zsh the default shell of my system, I started zsh in ~/.bashrc [cc lang=”bash” nowrap=”false”] . ~/bin/dotfiles/bash/env . ~/bin/dotfiles/bash/config . ~/bin/dotfiles/bash/completions . ~/bin/dotfiles/bash/aliases . ~/bin/dotfiles/bash/autojump # start zsh zsh [/cc] 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. [cc lang=”bash” nowrap=”false”] $ cat ~/.zshrc.orig >> ~/.zshrc [/cc] [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: [cc lang=”bash” nowrap=”false”] plugins=(git rails3 ruby osx brew rvm cp gem bundler coffee) [/cc] [RVM] I use RVM, below command is needed in ~/.zshrc [cc lang=”bash” nowrap=”false”] # RVM if [[ -s ~/.rvm/scripts/rvm ]] ; then source ~/.rvm/scripts/rvm ; fi [/cc] [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. [cc lang=”bash” nowrap=”false”] bindkey ‘^[[A’ history-beginning-search-backward bindkey ‘^[[B’ history-beginning-search-forward [/cc] [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. [cc lang=”bash” nowrap=”false”] $ cat ~/.bash_history | bash-history-to-zsh-history > /tmp/zsh_history $ cat ~/.zsh_history >> /tmp/zsh_history $ mv /tmp/zsh_history ~/.zsh_history [/cc] [Conclusion] As people always say “just do it”, probably so far the conclusion for zsh for me is “just use it” :)

Buy me a coffee
  • Post author: Samson Wu
  • Post link: 4398.html
  • Copyright Notice: All articles in this blog are licensed under BY-NC-SA unless stating additionally.
0%