zsh配置
[TOC]
基本說明
工欲善其事,必先利其器
日常項(xiàng)目中經(jīng)常使用shell處理命令行,那么一個(gè)好用的終端工具就是必備的器。
zsh作為一個(gè)基本的命令行,在很多平臺(tái)都可以直接安裝或者系統(tǒng)內(nèi)置。
zsh相比bash就是可以做大量的定制,能夠優(yōu)化一些操作。
Mac OSX配合 zsh能大大減少敲鍵盤的次數(shù)。
安裝
國(guó)內(nèi)安裝
github國(guó)內(nèi)訪問經(jīng)常卡頓,速度太慢。采用國(guó)內(nèi)gitee提供的倉庫,每日更新(gitee mirror 做的還不錯(cuò))
自己的一鍵安裝,(自動(dòng)安裝git kubectl docker zsh-autosuggestions zsh-syntax-highlighting)幾個(gè)常用插件
# yum or apt
yum install -y zsh
# apt install zsh
git clone --depth=1 https://gitee.com/mirrors/oh-my-zsh.git ~/.oh-my-zsh
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
chsh -s /bin/zsh
git clone --depth=1 https://github.com/zsh-users/zsh-autosuggestions.git ~/.oh-my-zsh/plugins/zsh-autosuggestions
git clone --depth=1 https://github.com/zsh-users/zsh-syntax-highlighting.git ~/.oh-my-zsh/plugins/zsh-syntax-highlighting
sed -i "s/plugins=(git)/plugins=(git kubectl docker zsh-autosuggestions zsh-syntax-highlighting)/g" ~/.zshrc
source ~/.zshrc
官方正常安裝
$ sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
# 有時(shí)候github 被墻了。可以試下下面
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
Mac自帶ZSH,切換開啟
chsh -s /bin/zsh
主要配置
安裝好以后,在當(dāng)前路徑創(chuàng)建了個(gè)隱藏文件:
ls ~/.oh-my-zsh
lib 提供了核心功能的腳本庫
tools 提供安裝、升級(jí)等功能的快捷工具
plugins 自帶插件的存在放位置
templates 自帶模板的存在放位置
themes 自帶主題文件的存在放位置
custom 個(gè)性化配置目錄,自安裝的插件和主題可放這里
關(guān)于 oh-my-zsh 插件的管理是很簡(jiǎn)單的,有兩個(gè)插件目錄:
- /Users/user/.oh-my-zsh/plugins
官方插件目錄,該目錄已經(jīng)預(yù)裝了很多實(shí)用的插件,只不過沒激活而已;
- /Users/user/.oh-my-zsh/custom/plugins:
oh-my-zsh 第三方插件目錄
開啟或者添加插件方法
編輯.zshrc
文件
找到plugins=(git)這一行,如果沒有添加。更改為如下
# vi .zshrc 找到plugins
plugins=(
git
extract
kubectl
zsh-syntax-highlighting
zsh-autosuggestions
z
)
主要推薦插件
一般oh-my-zsh的默認(rèn)插件加上這兩個(gè)插件就已經(jīng)能滿足90%人的需求了。
zsh-autosuggestions自動(dòng)提示插件
git clone --depth=1 git://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/plugins/zsh-autosuggestions
git depth=1 只獲取第一層文件,不獲取歷史,減少文件大小
zsh-syntax-highlighting 命令有語法高亮效果
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ~/.oh-my-zsh/plugins/zsh-syntax-highlighting
zsh修改主題
打開~/.zshrc文件, 我一般設(shè)置成random,這樣就可以經(jīng)常更換下主題,看到好的再固化。
vi .zshrc
ZSH_THEME=random