Zsh 安裝與配置
shell 是一款可用作交互式登錄的 shell 及腳本編寫的命令解釋器,Zsh 對(duì) Bourne shell 做出了大量改進(jìn),同時(shí)加入了 Bash、ksh 及 tcsh 的某些功能。(維基百科)
安裝 zsh
sudo apt install zsh
設(shè)置為默認(rèn)shell
sudo chsh -s `which zsh`
安裝 oh my zsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
如果報(bào)錯(cuò)使用國(guó)內(nèi)源
git clone https://mirrors.tuna.tsinghua.edu.cn/git/ohmyzsh.git && cd ohmyzsh/tools && REMOTE=https://mirrors.tuna.tsinghua.edu.cn/git/ohmyzsh.git sh install.sh
確保可以正常訪問github,否則打開終端時(shí)omz的自動(dòng)更新可能會(huì)卡住
解決無法自動(dòng)更新的問題
有三種解決方式:
關(guān)閉自動(dòng)更新
在 ~/.zshrc中取消注釋這一行:
zstyle ':omz:update' mode disabled
修改更新地址
cd ~/.oh-my-zsh
git remote set-url origin https://gitee.com/mirrors/oh-my-zsh.git
為git配置代理
git config --global http.proxy 'socks5://{ip}:{port}'
git config --global https.proxy 'socks5://{ip}:{port}'
配置主題
在~/.on-my-zsh/themes下存放著許多主題文件,可以通過修改~/.zshrc里的ZSH_THEME=""來設(shè)置
如果設(shè)置為random,每次打開終端都會(huì)使用隨機(jī)的主題
robbyrussell

agnoster

另行安裝 Powerlevel10k 主題

需要使用 MesloLGS NF 字體
安裝主題
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
在~/.zshrc中設(shè)置ZSH_THEME="powerlevel10k/powerlevel10k"
執(zhí)行以下命令將 Powerlevel10k 添加到配置文件中:
echo 'source ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k ' >>~/.zshrc
使配置文件生效:
source ~/.zshrc
安裝插件
命令補(bǔ)全
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
如果有問題用國(guó)內(nèi)源:
git clone https://gitee.com/hailin_cool/zsh-autosuggestions.git $ZSH_CUSTOM/plugins/zsh-autosuggestions
激活插件:
在~/.zshrc文件找到plugins=(),在其中添加zsh-autosuggestions,重啟終端
語法高亮
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
激活插件:
在~/.zshrc文件找到plugins=(git docker docker-compose zsh-syntax-highlighting zsh-autosuggestions),在其中添加zsh-syntax-highlighting,重啟終端
自動(dòng)跳轉(zhuǎn)
有時(shí)需要進(jìn)入一個(gè)比較深的目錄,比如/home/user/mail/inbox,cd進(jìn)去是比較麻煩的
autojump插件可以記錄訪問過的目錄,只需輸入 j 關(guān)鍵詞 回車,就能跳轉(zhuǎn)到以前訪問過的包含該關(guān)鍵詞的目錄
如果安裝了圖形界面,還可以用jo 關(guān)鍵詞,在文件管理器中打開
手動(dòng)安裝
git clone git://github.com/wting/autojump.git
cd autojump
./install.py
然后根據(jù)輸出的內(nèi)容編輯~/.zshrc
包管理器安裝
Debian系安裝autojump,RedHat系安裝autojump-zsh
Debian系還要根據(jù)/usr/share/doc/autojump/README.Debian的內(nèi)容配置~/.zshrc
完成后開啟新終端,使用autojump -h驗(yàn)證是否生效
oh-my-zsh配置中采用的是Powerline字體,而本人本地windows中不包含該系列字體,因此才會(huì)出現(xiàn)亂碼的問題。知道原因后那么就很好解決該問題了。 直接在windows中安裝powerline字體并在vscode中進(jìn)行設(shè)置!
解決步驟
下載powerline字體
下載鏈接:https://github.com/powerline/fonts
安裝字體
windows中安裝字體直接打開對(duì)應(yīng)的字體文件夾右鍵進(jìn)行安裝?。≒S:安裝一種powerline字體即可)
vscode中設(shè)置終端
在setting中搜索terminal選項(xiàng),然后修改字體為powerline字體即可。例如本人采用的是Space Mono For Powerline:
修改完成后字體顯示正常啦!果然是好看多了!??!
最后的配置文件:
export ZSH="$HOME/.oh-my-zsh"
ZSH_THEME="powerlevel10k/powerlevel10k"
plugins=(git zsh-autosuggestions zsh-syntax-highlighting)
source $ZSH/oh-my-zsh.sh
source ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
POWERLEVEL9K_DISABLE_CONFIGURATION_WIZARD=true