[TOC]
zsh+oh-my-zsh
oh-my-zsh 介紹
oh-my-zsh是基于zsh的功能做了一個擴(kuò)展,方便的插件管理、主題自定義,以及漂亮的自動完成效果
先安裝 zsh
brew info zsh
brew install zsh
再安裝 oh-my-zsh
curl -L https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | sh
或者
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
查看zsh版本
zsh --version
當(dāng)前默認(rèn)bash
echo $SHELL
確保zsh在/etc/shells列表中,修改默認(rèn)shell
檢查當(dāng)前的shell有那些
cat /etc/shells
chsh -s /bin/zsh
注銷用戶,重新登錄用戶
,確認(rèn)已經(jīng)是zsh,就可以了
提示 chsh:no changes made解決辦法
chsh -s /bin/zsh
dscl . -read /Users/$USER/ UserShell
exec su - $USER
zsh兼容bash_profile
zsh 不會讀取用戶目錄下的 .bash_profile
和 .bashrc 文件
,把你要在 ~/.bash_profile
里做的事寫在 ~/.zshrc
里。
或者,手工在 ~/.zshrc
里使用 source
命令執(zhí)行 ~/.bash_profile
也可以
方法是在 ~/.zshrc
中加入一行 source ~/.bash_profile
安裝可能錯誤Error
.zshrc:3: command not found: ^M
The temporary solution to that is changing your core.autocrlf git config setting to use input, given that you are on OSX. See #4402 (comment).
cd $ZSH
git config core.autocrlf input
git rm --cached -r .
git reset --hard
oh-my-zsh.sh: : parse error near ||
after Upgrade
vi the ~/.gitconfig file and set the autocrlf = false. then it works
Git clone errors if .gitconfig specifies autocrlf = true #4069
PATH set to RVM ruby but GEM_HOME and/or GEM_PATH not set
PATH set to RVM ruby but GEM_HOME and/or GEM_PATH not set
Add RVM set at ~/.zshrc
export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting
常用alias配置
# alias base
alias free='top -l 1 | head -n 10 | grep PhysMem'
alias ls='ls -hG'
alias ll='ls -l'
alias la='ls -a'
alias l='ls -CF'
alias cls='clear'
alias gs='git status'
alias gc='git commit'
alias gqa='git add .'
# alias docker
alias dkst="docker stats"
alias dkps="docker ps"
alias dkpsa="docker ps -a"
alias dkimgs="docker images"
alias dkcpup="docker-compose up -d"
alias dkcpdown="docker-compose down"
alias dkcpstart="docker-compose start"
alias dkcpstop="docker-compose stop"
export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting
zsh插件設(shè)置
修改 ~/.zshrc
文件中plugins=(git)
這個部分
這個是本人的插件
plugins=(
zsh_reload
git
osx
brew
colored-man-pages
sudo
autojump
zsh-autosuggestions
)
查看插件列表
ls ~/.oh-my-zsh/plugins | grep [pluginsName]
可以再插件在最前面加
!
表示禁用插件
- osx 希望在 OSX 中 插件生效,請一定加入這個配置
- zsh_reload ,這個增加了一個src的alias,可以重新reload zsh,尤其是當(dāng)一個新的程序安裝,zsh并不能像bash那樣立馬可以識別新的命令
- autojump 配合autojump 使用 j 命令直接快速進(jìn)入某個目錄
- zsh-syntax-highlighting,這個是當(dāng)你正在輸入一個命令的時候,顯示綠色,表示這個命令是有效的存在的,顯示紅色表示這個命令在系統(tǒng)中不存在,當(dāng)然不止這些。
- brew 這兩個是給OS X 的brew增加補(bǔ)全的。非這個系統(tǒng)請寫成 !brew-cask !brew
- colored-man-pages 顧名思義,彩色的man很贊!
- sudo 當(dāng)你輸入一個命令發(fā)現(xiàn)需要root權(quán)限,通常只能按方向上鍵,然后光標(biāo)移到頭部,加入sudo,但是有了這個插件,不用再移動光標(biāo)到頭部了,直接兩下 ESC, sudo就會自動加入到最前面。。。
自動提示命令 zsh-autosuggestions
輸入命令時,終端會自動提示你接下來可能要輸入的命令
- 克隆倉庫到本地
~/.oh-my-zsh/custom/plugins
路徑
git clone git://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
在~/.zshrc
中添加
plugins=(
zsh-autosuggestions
)
可能看不到變化,可能你的字體顏色太淡
vim ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
修改 ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=10'
語法高亮
zsh-syntax-highlighting 安裝分源碼和管理工具安裝
# if use brew install
brew install zsh-syntax-highlighting
echo "source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ${ZDOTDIR:-$HOME}/.zshrc
# use git install
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $ZSH_CUSTOM/plugins/zsh-syntax-highlighting
echo "source \$ZSH_CUSTOM/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ${ZDOTDIR:-$HOME}/.zshrc
插件推薦
- rsync 增加了幾個rsync的alias,簡化操作
zsh 美化
主題預(yù)覽
https://github.com/robbyrussell/oh-my-zsh/wiki/External-themes
其中主題 robbyrussell
dst
agnoster
duellj
可以嘗試一下
autojump 配置
只在 zsh
中配置了插件
plugins=(
git
zsh_reload
autojump
)
沒有安裝autojump是不能使用的
brew install autojump
安裝完成后會有提示,因?yàn)槭鞘褂昧?code>zsh,將下面的配置添加到 ~/.bash_profile
后
# env of autojump
[ -f /usr/local/etc/profile.d/autojump.sh ] && . /usr/local/etc/profile.d/autojump.sh
設(shè)置完成后,加載配置source ~/.bash_profile
,然后就可以使用 j [路徑短寫]
來跳轉(zhuǎn)
autojump 是基于cd去過的路徑,沒用去過的路徑無法短寫跳轉(zhuǎn)
路徑跳轉(zhuǎn)錯誤可以使用
autojump --purge
來清理錯誤路徑