1. 程式人生 > >Oh My Zsh 強大炫酷的Shell

Oh My Zsh 強大炫酷的Shell

文章目錄

前言

Zsh介紹

  • zsh 完全相容 bash
  • zsh 官網:http://www.zsh.org/
  • zsh具有強大的可定製的特點,支援許多外掛,補全功能也強大很多.但是卻配置起來十分的麻煩,但有了oh-my-zsh之後,一切變得簡單起來了

Oh My Zsh

  • Oh My Zsh 是一款社群驅動的命令列工具
  • oh my zsh :https://github.com/robbyrussell/oh-my-zsh
  • 有許多精美的主題和強大的外掛,還有比bash更強大別名功能,美觀方便。也幫我們整理了一些常用的 Zsh 擴充套件功能和主題

Linux

這裡是Debian系的系統deepin來舉例

安裝zsh

檢視系統支援的shell

cat /etc/shells

在這裡插入圖片描述
若沒有zsh則安裝就是

sudo apt-get install -y zsh

安裝oh my zsh

若沒有git,需要先安裝

sudo apt-get install -y git

然後就直接開始下載oh my zsh,會安裝到當前使用者的家目錄,並使用與當前使用者

wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O - | sh

先把使用者的預設Shell切換為zsh

chsh -s /bin/zsh

關閉終端再開啟就應該是這樣
在這裡插入圖片描述

配置oh my zsh

主題

編輯它的配置檔案

vim ~/.zshrc

那個就是他的主題的選擇
在這裡插入圖片描述
改成現在很熱門的主題agnoster
其他主題

ZSH_THEME="agnoster"

配置字型

若出現亂碼則是缺少Powerline字型

wget https://raw.githubusercontent.com/powerline/powerline/develop/font/10-powerline-symbols.conf
wget https://raw.githubusercontent.com/powerline/powerline/develop/font/PowerlineSymbols.otf
sudo mkdir /usr/share/fonts/OTF
sudo cp 10-powerline-symbols.conf /usr/share/fonts/OTF/
sudo mv 10-powerline-symbols.conf /etc/fonts/conf.d/
sudo mv PowerlineSymbols.otf /usr/share/fonts/OTF/

重啟終端
在這裡插入圖片描述

其他主題https://github.com/robbyrussell/oh-my-zsh/wiki/Themes

外掛

vim ~/.zshrc

這裡就是啟用的外掛

在這裡插入圖片描述
自帶外掛都在~/.oh-my-zsh/plugins

實用的外掛

z

快速訪問目錄
自帶有,直接新增

在這裡插入圖片描述
zsh-syntax-highlighting

檢查shell命令語法
官網

怎麼使用舉個例

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

效果:
在這裡插入圖片描述
web-search

終端中直接進行網頁搜尋
自帶

在這裡插入圖片描述
extract

壓縮直接用x就可以完成
自帶

x test.tar.gz

wd

對目錄進行對映
自帶

在這裡插入圖片描述
sudo

按兩下ESC在命令開頭增加sudo命令
自帶

encode64

Base64 編碼
自帶

urltools

url編碼工具,有urlencodeurldecode
自帶

mac

自帶了zsh,所以首先要安裝iTerm2這個終端利器

安裝iTerm2

官網下載

安裝 oh my zsh

sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"

預設Shell切換到zsh

cash -s /bin/zsh

配置 oh my zsh

與上面linux相同

配置字型

有些主題需要 Meslo 字型支援,要不然會出現亂碼
下載地址

開啟 iTerm2,按Command + ,鍵,開啟 Preferences 配置介面,然後Profiles -> Text -> Font -> Chanage Font,選擇 Meslo LG M Regular for Powerline 字型。
詳細