Cygwin的默认Shell是bash,如果要把它换成更有交互性的zsh应该怎么配置呢?

首先是安装zsh。如果你有apt-cyg的话,很简单,只需要在cygwin里执行下面的命令

apt-cyg install zsh

其次是把Cygwin的默认shell从bash改成zsh。

Cygwin使用的终端模拟器是MinTTY,如果要让MinTTY一启动就使用zsh的话,可以把MinTTY的快捷方式从:

C:\Cygwin\bin\mintty.exe -i /Cygwin-Terminal.ico -

改成

C:\Cygwin\bin\mintty.exe -i /Cygwin-Terminal.ico -e /usr/bin/zsh -l -

这样MinTTY默认的shell就是zsh了。可是这个zsh光秃秃的,缺少很多功能,需要对它进行配置。

oh-my-zsh

oh-my-zsh是一款很火的zsh配置框架,在Github上有好多星星。可惜安装了之后,在Cygwin上的运行速度不尽人意,在命令提示符下不输入命令,直接敲回车,都会卡顿一下,半天才出内容。

oh-my-zsh无法在我的Cygwin上使用,囧。

prezto

Prezto是一款类似oh-my-zsh的配置框架,虽然不如oh-my-zsh流行,但是人家轻量级啊。

安装过程的话,按照prezto主页的说明,首先要克隆prezto的仓库:

git clone –recursive https://github.com/sorin-ionescu/prezto.git “${ZDOTDIR:-$HOME}/.zprezto”

然后将HOME目录下的所有zsh的配置文件全删掉(请确保你没有重要信息在里面):

cd; rm .z*

然后执行下面的脚本:

setopt EXTENDED_GLOB
for rcfile in "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/^README.md(.N); do
  ln -s "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile:t}"
done

上面的脚本就是把HOME目录下的zsh配置文件软链接到prezto所在的目录.zprezto,用ls -l .z*查看:

lrwxrwxrwx  1 ... .zlogin -> /home/user/.zprezto/runcoms/zlogin
lrwxrwxrwx  1 ... .zlogout -> /home/user/.zprezto/runcoms/zlogout
lrwxrwxrwx  1 ... .zpreztorc -> /home/user/.zprezto/runcoms/zpreztorc
lrwxrwxrwx  1 ... .zprofile -> /home/user/.zprezto/runcoms/zprofile
-rw-------  1 ... .zsh_history
lrwxrwxrwx  1 ... .zshenv -> /home/user/.zprezto/runcoms/zshenv
lrwxrwxrwx  1 ... .zshrc -> /home/user/.zprezto/runcoms/zshrc

需要注意的是,prezto的配置文件是.zpreztorc而不是.zshrc,下面是我对.zpreztorc所做的编辑:

# 使用vi建绑定
zstyle ':prezto:module:editor' key-bindings 'vi'

# 使用主题cloud(因为默认的主题需要安装特殊的字体)
zstyle ':prezto:module:prompt' theme 'cloud'

好了,我的zsh在cygwin下飞起来了。

(完)