Oh-My-Zsh

MacOS X 安装 oh-my-zsh autojump

2016-11-11  本文已影响6197人  木猫尾巴

[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]

可以再插件在最前面加 ! 表示禁用插件

插件推荐

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 可以尝试一下

自动提示命令

输入命令时,终端会自动提示你接下来可能要输入的命令

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
上一篇 下一篇

猜你喜欢

热点阅读