Mac安裝oh my zsh插件autojump、zsh-syntax-highlighting、zsh-autosuggestion

一、安裝oh my zsh

1. zsh是什么???

Zsh 是一款強大的虛擬終端,既是一個系統(tǒng)的虛擬終端,也可以作為一個腳本語言的交互解析器。

2. 如何查看是否安裝了zsh???

  • 在終端輸入:
$ zsh --version
  • 我的輸出:
zsh 5.7.1 (x86_64-apple-darwin19.0)

這表示我已經(jīng)安裝了zsh

3. oh my zsh

① 安裝

可以通過 curlwget 兩種方式來安裝,用一條命令即可安裝。

  • curl安裝
$ sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
  • wget安裝
$ sh -c "$(wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"

② 簡單配置

設(shè)置固定主題
  • 終端輸入:open ~/.zshrc
  • 找到ZSH_THEME="robbyrussell",這里,已經(jīng)設(shè)置了默認主題robbyrussell,若要修改主題請按此格式:ZSH_THEME="主題名稱"
  • 保存文件,重新打開終端
設(shè)置隨機主題
  • 終端輸入:open ~/.zshrc
  • 主題設(shè)置為:ZSH_THEME="random"
  • 這樣每次打開終端時,主題都是隨機的。
  • 例:下一次打開終端時,會輸出形如[oh-my-zsh] Random theme 'xiong-chiamiov' loaded的語句,'xiong-chiamiov'即主題名稱,如果你喜歡這個主題,可以把它設(shè)置在你的.zshrc中。
查看主題名稱

oh my zsh 默認自帶了一些默認主題,存放在 ~/.oh-my-zsh/themes目錄中。我們可以查看這些主題:

$ cd ~/.oh-my-zsh/themes && ls

③ 卸載oh my zsh

$ uninstall_oh_my_zsh
   Are you sure you want to remove Oh My Zsh? [y/N]  Y

④ oh my zsh 的自動更新提示誤觸關(guān)掉了解決辦法

$ upgrade_oh_my_zsh

二、安裝autojump

插件功能:實現(xiàn)目錄間快速跳轉(zhuǎn),想去哪個目錄直接 j + 目錄名,不用再頻繁的 cd 了!

1. 安裝步驟

  • 在終端輸入:
$ brew install autojump
  • 輸出:
==> Downloading https://homebrew.bintray.com/bottles/autojump-22.5.3.catalina.bo
######################################################################## 100.0%
==> Pouring autojump-22.5.3.catalina.bottle.tar.gz
==> Caveats
Add the following line to your ~/.bash_profile or ~/.zshrc file (and remember
to source the file to update your current session):
  [ -f /usr/local/etc/profile.d/autojump.sh ] && . /usr/local/etc/profile.d/autojump.sh

If you use the Fish shell then add the following line to your ~/.config/fish/config.fish:
  [ -f /usr/local/share/autojump/autojump.fish ]; and source /usr/local/share/autojump/autojump.fish

zsh completions have been installed to:
  /usr/local/share/zsh/site-functions
==> Summary
??  /usr/local/Cellar/autojump/22.5.3: 20 files, 169.3KB
image.png
  • 根據(jù)提示,在~/.zshrc文件中加入:
 [ -f /usr/local/etc/profile.d/autojump.sh ] && . /usr/local/etc/profile.d/autojump.sh
  • 使用source命令更新配置文件:
$ source ~/.zshrc
  • 這樣就可以根據(jù)你的cd歷史記錄,使用j命令快速跳轉(zhuǎn)到目標(biāo)目錄,而不需要多次cd啦~

三、安裝zsh-syntax-highlighting

插件功能:這個包為shell zsh提供語法突出顯示。它允許高亮顯示在zsh提示符下輸入到交互式終端的命令。這有助于在運行命令之前檢查它們,特別是在捕獲語法錯誤方面。
例:在你輸入某個命令時,如果該命令不存在,那么它顯示為紅色;否則,它會變成綠色。

1. 文檔

2. 安裝步驟

  • 在終端輸入:
$ brew install zsh-syntax-highlighting
  • 輸出:
==> Downloading https://homebrew.bintray.com/bottles/zsh-syntax-highlighting-0.7.1.catal
######################################################################## 100.0%
==> Pouring zsh-syntax-highlighting-0.7.1.catalina.bottle.tar.gz
==> Caveats
To activate the syntax highlighting, add the following at the end of your .zshrc:
  source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

If you receive "highlighters directory not found" error message,
you may need to add the following to your .zshenv:
  export ZSH_HIGHLIGHT_HIGHLIGHTERS_DIR=/usr/local/share/zsh-syntax-highlighting/highlighters
==> Summary
??  /usr/local/Cellar/zsh-syntax-highlighting/0.7.1: 27 files, 164.4KB
image.png
  • ~/.zshrc文件中加入:
source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
  • 使用source命令更新配置文件:
$ source ~/.zshrc

四、安裝zsh-autosuggestion

插件功能:輸入命令時可提示自動補全(灰色部分),按tab鍵(→ )即可補全。

1. 文檔:

2. 安裝步驟

  • 在終端輸入:
git clone https://github.com/zsh-users/zsh-autosuggestions ~/.zsh/zsh-autosuggestions
  • 輸出:
Cloning into '/Users/xxx/.zsh/zsh-autosuggestions'...
remote: Enumerating objects: 11, done.
remote: Counting objects: 100% (11/11), done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 2396 (delta 2), reused 3 (delta 1), pack-reused 2385
Receiving objects: 100% (2396/2396), 545.28 KiB | 5.00 KiB/s, done.
Resolving deltas: 100% (1533/1533), done.
  • ~/.zshrcs文件中加入:
source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh
  • 使用source命令更新配置文件:
$ source ~/.zshrc

五、參考資料

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容