本文以Ubuntu 12.04 LTS为例,安装目前比较流行的zsh的配置oh-my-zsh。 oh-my-zsh最初是在OS X上供人使用,使用方法见此处。在Ubuntu上安装oh-my-zsh稍有不同。

安装

先安装zsh和git,同时移除之前可能的oh-my-zsh的安装。

?
1
2
3
4
sudo apt-get install zsh git
if [ -d ~/.oh-my-zsh ]; then
     rm -r ~/.oh-my-zsh
fi

手动安装zsh是用于Ubuntu的 sh 比较诡异,不识别 source 这个指令。装好zsh后仿OS X

?
1
wget https: //github .com /robbyrussell/oh-my-zsh/raw/master/tools/install .sh -O - | zsh

然后把shell切换成zsh,并重启计算机。

?
1
2
chsh -s ` which zsh`
sudo shutdown -r 0

关于这个诡异问题的详细讨论见github上此issue

配置

oh-my-zsh有大量精美主题托管在项目中,可以在此预览 https://github.com/robbyrussell/oh-my-zsh/wiki/themes,我看中了其中最拉风的一款agnoster。把配置过程记录如下。

  • 为了能够显示诸如分支(branch)、闪电(这个符号应该指拿到root权限)、错误(红色叉叉)、后台(一个齿轮)的各种符号,必须使用一个patch过的字体,在ubuntu下默认是Ubuntu Mono,OS X下坐着配的是Menlo,很多常见的等宽字体都打好了patch,当然也可以自己手动打patch。
    ?
    1
    cd ~/.fonts/ && git clone https: //github .com /scotu/ubuntu-mono-powerline .git && cd ~
  • 在 ~/.zshrc 把主题设置为 agnoster
  • 在 ~/.zshrc 设定 DEFAULT_USER 变量可以使得即使登陆在本机(即非SSH到远程)时也能显示“user@hostname”

这是我做的效果,Solarized Dark colorscheme这个配色没有适用于Ubuntu Terminal的。

以下是我的 .zshrc ,只开了git一个plugin,还有很多plugin在 ~/.oh-my-zsh/plugin/ 目录下,原来的sublime的plugin有点bug,我就放在我的.zshrc的配置文件里面了。

12345678910111213141516171819202122232425262728293031323334353637383940414243
 
           
# Path to your oh-my-zsh configuration.
ZSH = $HOME/.oh-my-zsh
 
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
# ZSH_THEME="robbyrussell"
ZSH_THEME = "agnoster"
 
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
 
# Set to this to use case-sensitive completion
# CASE_SENSITIVE="true"
 
# Comment this out to disable weekly auto-update checks
# DISABLE_AUTO_UPDATE="true"
 
# Uncomment following line if you want to disable colors in ls
# DISABLE_LS_COLORS="true"
 
# Uncomment following line if you want to disable autosetting terminal title.
# DISABLE_AUTO_TITLE="true"
 
# Uncomment following line if you want red dots to be displayed while waiting for completion
# COMPLETION_WAITING_DOTS="true"
 
# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
plugins =(git )
 
alias st = '/usr/bin/sublime-text'
 
source $ZSH/oh-my-zsh.sh
 
# Customize to your needs...
export PATH =/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
 
# optionally set DEFAULT_USER in ~/.zshrc to your regular username to hide the “user@hostname” info when you’re logged in as yourself on your local machine.
DEFAULT_USER =tangkai@virtual-machine