centos使用--zsh


為何要換成zsh,主要是兩點吧

1. 界面更漂亮,換一種心情  
2. 更高級的功能,提高效率  

1 切換到zsh

使用root用戶登錄,下面的操作基本都沒有root的困擾,如果非root用戶請切換至root用戶操作。

1.1 查看系統當前的shell

echo $SHELL
返回結果如下:
/bin/bash
默認的shell一般都是bash

1.2 查看bin下是否有zsh包

cat /etc/shells
返回結果如下:

/bin/sh
/bin/bash
/sbin/nologin
/bin/dash
/bin/tcsh
/bin/csh

默認沒有安裝zsh

1.3 安裝zsh包

yum -y install zsh

安裝完成后查看shell列表
cat /etc/shells

返回結果如下:

/bin/sh
/bin/bash
/sbin/nologin
/bin/dash
/bin/tcsh
/bin/csh
/bin/zsh

1.4 切換shell至zsh

chsh -s /bin/zsh

返回結果:
Changing shell for root.
Shell changed.

按提示所述,shell已經更改為zsh了,現在查看一下系統當前使用的shell,
echo $SHELL
返回結果如下:
/bin/bash
重啟過后,使用代碼查看當前使用的shell
echo $SHELL
返回結果:
/bin/zsh

得到如此結果,證明shell已經切換成功了。

2 安裝oh-my-zsh

2.1 oh-my-zsh源碼是放在github上的,所以先要安裝git

命令如下:
yum -y install git
wget https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | sh

如果顯示如下界面表示成功:

         __                                     __   
  ____  / /_     ____ ___  __  __   ____  _____/ /_  
 / __ \/ __ \   / __ `__ \/ / / /  /_  / / ___/ __ \ 
/ /_/ / / / /  / / / / / / /_/ /    / /_(__  ) / / / 
\____/_/ /_/  /_/ /_/ /_/\__, /    /___/____/_/ /_/  
                        /____/                       ....is now installed!
Please look over the ~/.zshrc file to select plugins, themes, and options.

p.s. Follow us at https://twitter.com/ohmyzsh.

p.p.s. Get stickers and t-shirts at http://shop.planetargon.com.

2.2 修改配置

主要是修改 文件 ~/.zshrc

2.2.1 修改主題

~/.oh-my-zsh/themes文件夾下有主題的列表

樣式參考 https://github.com/robbyrussell/oh-my-zsh/wiki/Themes

推薦

ZSH_THEME='ys'  
ZSH_THEME='agnoster'

2.2.2 修改插件

~/.oh-my-zsh/plugins文件夾下有可用的插件列表

更換Plugin

plugins=(git z extract)
git  顯示git信息  
z    可以用來快速跳轉  
extract 解壓文件插件,所有的文件直接 x filename 即可,不用再記憶各類參數

修改完后,如果需要在當前shell中生效,需要執行

source ~/.zshrc

還可以自己下載插件

安裝zsh-syntax-highlighting插件

同樣地,我們要先下載它的源碼,但在這里,我們可以利用一下oh-my-zsh的插件管理功能:

    cd ~/.oh-my-zsh/custom/plugins
    git clone git://github.com/zsh-users/zsh-syntax-highlighting.git

然后,我們打開~/.zshrc文件,找到以下段落;

    # Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
    # Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
    # Example format: plugins=(rails git textmate ruby lighthouse)
    # Add wisely, as too many plugins slow down shell startup.
    plugins=(git)

按照注釋中的提示改成plugins=(git zsh-syntax-highlighting)即可。

3 使用技巧

  1. 連按兩次Tab會列出所有的補全列表並直接開始選擇,補全項可以使用 ctrl+n/p/f/b上下左右切換
  2. 命令選項補全。在zsh中只需要鍵入 tar -<tab> 就會列出所有的選項和幫助說明
  3. 命令參數補全。鍵入 kill <tab> 就會列出所有的進程名和對應的進程號
  4. 更智能的歷史命令。在用或者方向上鍵查找歷史命令時,zsh支持限制查找。比如,輸入ls,然后再按方向上鍵,則只會查找用過的ls命令。而此時使用則會仍然按之前的方式查找,忽略 ls
  5. 多個終端會話共享歷史記錄
  6. 智能跳轉,安裝了 autojump 之后,zsh 會自動記錄你訪問過的目錄,通過 j 目錄名 可以直接進行目錄跳轉,而且目錄名支持模糊匹配和自動補全,例如你訪問過 hadoop-1.0.0 目錄,輸入j hado 即可正確跳轉。j --stat 可以看你的歷史路徑庫。
  7. 目錄瀏覽和跳轉:輸入 d,即可列出你在這個會話里訪問的目錄列表,輸入列表前的序號,即可直接跳轉。
  8. 在當前目錄下輸入 .. 或 ... ,或直接輸入當前目錄名都可以跳轉,你甚至不再需要輸入 cd 命令了。在你知道路徑的情況下,比如 /usr/local/bin 你可以輸入 cd /u/l/b 然后按進行補全快速輸入
  9. 通配符搜索:ls -l **/*.sh,可以遞歸顯示當前目錄下的 shell 文件,文件少時可以代替 find。使用 **/ 來遞歸搜索
  10. 擴展環境變量,輸入環境變量然后按 就可以轉換成表達的值
  11. 在 .zshrc 中添加 setopt HIST_IGNORE_DUPS 可以消除重復記錄,也可以利用 sort -t ";" -k 2 -u ~/.zsh_history | sort -o ~/.zsh_history 手動清除

卡頓現象,發現每次執行命令都要運行git 檢查status信息,可以使用下面命令

關閉

git config --global oh-my-zsh.hide-status 1  

打開

git config --global oh-my-zsh.hide-status 0  
# root @ WENGINE in /var/www/html on git:feature-apply_config x [13:32:48] 
$ git config --global oh-my-zsh.hide-status 1

# root @ WENGINE in /var/www/html [13:33:24] 
$ git config --global oh-my-zsh.hide-status 0

# root @ WENGINE in /var/www/html on git:feature-apply_config x [13:33:33] 
$ 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM