Linux和Mac系统默认的shell 都是bash,但是真正强大的shell应属于zsh,而且完全监控bash,是shell中的终极杀手,有很多bash所没有的功能,但是zsh的初期配置太过繁琐,流行率一直不高,直到有个叫Robby Russell的家伙在github上开发了oh-my-zsh项目,使大家使用zsh的便捷性大大提高。
由于在公司的电脑是windows,就折腾了下cygwin,并且安装了zsh,这样做起维护方便很多了,而且我把autojump项目也集成一起,最后写了一个自动安装的脚本,可以自动从当前bash环境下安装Oh-my-zsh, autojump并初始化zsh。目前只支持Ubuntu, CentOS, Debian。
我在网上收集这这套zsh profile支持的插件有(git autojump history history-substring-search systemadmin systemd), 具体使用方案可以查看插件源代码~.oh-my-zsh/plugins/。
autojump使用方法请看autojump的官方文档。https://github.com/wting/autojump
history-substring-search 搜索历史明亮非常强大,强大到令你乍舌。
systemadmin集成了很多SA常用的命令。
systemd 对于centos7以后的systemctl精简比较智能。
#!/bin/bash 
#Author:Shanker 
#set -x 
#set -u 
clearhacker 
  
echo ""
echo "#############################################################"
echo "# Automatically to  Install oh-my-zsh and initialize it     #"
echo "# Intro: https://github.com/sangrealest/shanker             #"
echo "# Author: Shanker<shanker@yeah.net>                         #"
echo "#############################################################"
echo ""
#if [ `id -u` -ne 0 ] 
#then 
#    echo "Need root to run is, try with sudo" 
#    exit 1 
#fi 
function checkOs(){ 
    if [ -f /etc/RedHat-release ] 
    then
        OS="CentOS"
    elif [ ! -z "`cat /etc/issue | grep -i bian`" ] 
    then
        OS="Debian"
    elif [ ! -z "`cat /etc/issue | grep -i ubuntu`" ] 
    then
        OS="Ubuntu"
    else
        echo "Not supported OS"
        exit 1 
    fi
} 
function installSoftware(){ 
if [ "$OS" == 'CentOS' ] 
then
    sudo yum -y install zsh git 
else
    sudo apt-get -y install zsh git 
fi
zshPath="`which zsh`"
} 
function downloadFile(){ 
    cd ~ 
    git clone https://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh 
    git clone https://github.com/joelthelion/autojump.git 
    git clone https://github.com/sangrealest/initzsh
} 
function installAutojump(){ 
    cd ~/autojump
    ./install.py 
cat >>~/.zshrc<<EOF 
[[ -s ~/.autojump/etc/profile.d/autojump.sh ]] && source ~/.autojump/etc/profile.d/autojump.sh 
autoload -U compinit && compinit -u 
EOF 
} 
function configZsh(){ 
    if [ -f ".zsh_history" ] 
    then
        mv .zsh_history{.,backup} 
    fi
    sudo chsh -s "$zshPath"
    cp ~/initzsh/zshrc ~/.zshrc 
} 
function main(){ 
checkOs 
installSoftware 
downloadFile 
configZsh 
installAutojump 
} 
main
如果是cygwin使用zsh,只需要在你的.bashrc里面加上一行 /bin/zsh即可。
效果如图:


