歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> bash環境下自動安裝並初始化oh-my-zsh & autojump zsh

bash環境下自動安裝並初始化oh-my-zsh & autojump zsh

日期:2017/2/28 13:54:51   编辑:Linux教程

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<[email protected]> #"
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即可。
效果如圖:

Copyright © Linux教程網 All Rights Reserved