[TOC]
oh-my-zsh 介绍
oh-my-zsh是基于zsh的功能做了一个扩展,方便的插件管理、主题自定义,以及漂亮的自动完成效果
先安装 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
当前默认bash
echo $SHELL
确保zsh在/etc/shells列表中,修改默认shell
chsh -s /bin/zsh
重新打开终端,已经是zsh了 完事
zsh兼容bash_profile
zsh 不会读取用户目录下的 .bash_profile
和 .bashrc 文件
,把你要在 ~/.bash_profile
里做的事写在 ~/.zshrc
里。
或者,手工在 ~/.zshrc
里使用 source
命令执行 ~/.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 cls='clear'
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$PATH:$GOROOT/bin
export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting
插件设置
修改 ~/.zshrc
文件中plugins=(git)
这个部分
这个是本人的插件
plugins=(git osx zsh_reload autojump brew colored-man-pages sudo)
查看插件列表
ls ~/.oh-my-zsh/plugins | grep [pluginsName]
可以再插件在最前面加
!
表示禁用插件
- osx 希望在 OSX 中 插件生效,请一定加入这个配置
- zsh_reload ,这个增加了一个src的alias,可以重新reload zsh,尤其是当一个新的程序安装,zsh并不能像bash那样立马可以识别新的命令
- autojump 配合autojump 使用 j 命令直接快速进入某个目录
- zsh-syntax-highlighting,这个是当你正在输入一个命令的时候,显示绿色,表示这个命令是有效的存在的,显示红色表示这个命令在系统中不存在,当然不止这些。
- brew 这两个是给OS X 的brew增加补全的。非这个系统请写成 !brew-cask !brew
- colored-man-pages 顾名思义,彩色的man很赞!
- sudo 当你输入一个命令发现需要root权限,通常只能按方向上键,然后光标移到头部,加入sudo,但是有了这个插件,不用再移动光标到头部了,直接两下 ESC, sudo就会自动加入到最前面。。。
插件推荐
- rsync 增加了几个rsync的alias,简化操作
autojump 配置
只在 zsh
中配置了插件,没有安装autojump是不能使用的
brew install autojump
安装完成后会有提示,因为是使用了zsh
,将下面的配置添加到 ~/.bash_profile
后
# env of autojump
[ -f /usr/local/etc/profile.d/autojump.sh ] && . /usr/local/etc/profile.d/autojump.sh
设置完成后,加载配置source ~/.bash_profile
,然后就可以使用 j [路径短写]
来跳转
autojump 是基于去过的路径,新路径无法短写跳转
zsh 美化
主题预览
https://github.com/robbyrussell/oh-my-zsh/wiki/External-themes
其中主题 robbyrussell
dst
agnoster
duellj
可以尝试一下
自动提示命令
输入命令时,终端会自动提示你接下来可能要输入的命令
- 克隆仓库到本地
~/.oh-my-zsh/custom/plugins
路径
git clone git://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
在~/.zshrc
中添加
plugins=(zsh-autosuggestions git)
可能看不到变化,可能你的字体颜色太淡
vim ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
修改 ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=10'
语法高亮
brew install zsh-syntax-highlighting
.zshrc
中加入
source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
网友评论