Liunx 安裝配置zsh和oh-my-zsh 替換 bash

一、前言

本文將基於 Liunx 環境安裝配置 zsh 和 oh-my-zsh 替換 bash

oh my zsh

Liunx默認shell是單調的bash,而zsh比較高大上,bash有的功能,zsh基本上都有,並且功能強大,擁有很多插件與主題...

  1. Github 地址:https://github.com/ohmyzsh/ohmyzsh
  2. 官網地址: http://ohmyz.sh/

二、安裝 zsh

小編將基於centos7.x 環境進行演示

# 查看當前使用的shell
echo $SHELL
# 查看shell列表確認是否安裝zsh 或 直接執行 `zsh --version`
cat /etc/shells

# 安裝zsh
yum -y install zsh
# 查看shell列表
cat /etc/shells
# 切換shell為zsh 【 重新恢復到bash命令 : `chsh -s /bin/bash root` 】 - 末尾`root`標識為`root`用戶配置
chsh -s /bin/zsh
# 重啟服務器
reboot
# 查看當前shell
echo $SHELL
Liunx 安裝配置zsh和oh-my-zsh 替換 bash

三、安裝 oh my zsh

# 安裝 git
yum install -y git
# 安裝 oh-my-zsh
wget https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | sh

# 成功則如下: --------------------------------------------------------------------------
__ __
____ / /_ ____ ___ __ __ ____ _____/ /_
/ __ \\/ __ \\ / __ `__ \\/ / / / /_ / / ___/ __ \\
/ /_/ / / / / / / / / / / /_/ / / /_(__ ) / / /
\\____/_/ /_/ /_/ /_/ /_/\\__, / /___/____/_/ /_/
/____/ ....is now installed!

溫馨小提示:

root用戶 安裝後

  1. oh-my-zsh 安裝目錄: /root/.oh-my-zsh
  2. zsh 配置文件位置: /root/.zshrc

四、oh-my-zsh 配置

1、安裝主題

主題選擇:https://github.com/ohmyzsh/ohmyzsh/wiki/themes

這裡小編選擇 ys 主題進行安裝 : https://blog.ysmood.org/my-ys-terminal-theme/

# 修改主題:
vim ~/.zshrc
# 將ZSH_THEME改成ys 【 zsh的默認主題為 `robbyrussell` (它不會把當前的工作路徑全部展示出來) 注:=右邊一定不要有空格,否則會報錯找不到此主題 】

ZSH_THEME="ys"
# 更新配置
source ~/.zshrc
Liunx 安裝配置zsh和oh-my-zsh 替換 bash

2、安裝插件

① incr.zsh 自動補全插件 -> http://mimosa-pudica.net/zsh-incremental.html

# 下載incr.zsh插件,並將插件放到oh-my-zsh目錄的插件庫下
cd ~/.oh-my-zsh/plugins
wget http://mimosa-pudica.net/src/incr-0.2.zsh
source incr*.zsh

# 更新配置
source ~/.zshrc

② zsh-syntax-highlighting 命令行高亮顯示插件

# 下載
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

# 修改配置
vim ~/.zshrc
# 將 plugins=(git) 改為 plugins=(git zsh-syntax-highlighting) 即可 【 注: 多個插件用空格分隔 】

# 更新配置
source ~/.zshrc
Liunx 安裝配置zsh和oh-my-zsh 替換 bash

③ zsh-autosuggestions 歷史命令記錄插件

# 下載
git clone git://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions

# 修改配置
vim ~/.zshrc
# 將 plugins=(git) 改為 plugins=(git zsh-autosuggestions) 即可 【 注: 多個插件用空格分隔 】

# 更新配置
source ~/.zshrc
Liunx 安裝配置zsh和oh-my-zsh 替換 bash

如需其它插件可自行谷歌哦~

Liunx 安裝配置zsh和oh-my-zsh 替換 bash

3、問題:vim提示衝突

使用自動補全插件可能會與vim的提示功能衝突解決:將 ~/.zcompdump* 刪除即可

rm -rf ~/.zcompdump*
exec zsh

4、設置自動更新 oh-my-zsh

默認情況下,當oh-my-zsh有更新時,都會提示

①如果希望讓oh-my-zsh自動更新,則修改 ~/.zshrc 配置如下

# 修改配置
vim ~/.zshrc

# 新增配置
DISABLE_UPDATE_PROMPT=true

# 更新配置:
source ~/.zshrc

② 手動更新則執行

upgrade_oh_my_zsh

5、卸載 oh-my-zsh

uninstall_oh_my_zsh

五、總結

個人感覺 oh my zsh 很給力,用起來很舒服,是個好玩意兒 ~

Liunx 安裝配置zsh和oh-my-zsh 替換 bash


分享到:


相關文章: