手机版
你好,游客 登录 注册
背景:
阅读新闻

bash环境下自动安装并初始化oh-my-zsh & autojump zsh

[日期:2016-01-25] 来源:Linux社区  作者:shanker [字体: ]

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即可。
效果如图:

bash环境下自动安装并初始化oh-my-zsh & autojump zsh

本文永久更新链接地址http://www.linuxidc.com/Linux/2016-01/127841.htm

linux
相关资讯       oh-my-zsh 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款