blog/linux/linux安装使用zsh和oh my zsh

linux安装使用zsh和oh my zsh

安装使用zsh 和 oh my zsh

  1. 先安装zsh

yum install zsh

  1. 切换zsh

chsh -s /bin/zsh

设置用户默认zsh

sudo usermod -s /bin/zsh username

安装oh my zsh

使用 curl

$ sh -c “$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

或者 使用wget

$ sh -c “$(wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)”

如果 下载可能很慢

手动配置
使用码云地址下载再安装

  1. 克隆仓库

    git clone https://gitee.com/zhou_jiajian/ohmyzsh.git

或者自己github地址

git clone git@github.com:wx11055/oh-my-zsh.git

  1. 更改仓库名为.oh-my-zsh

mv ohmyzsh .oh-my-zsh

  1. 改写 .zshrc文件

cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc

  1. 改变shell

chsh -s /bin/zsh

  1. 设置zsh 为默认shell

source ~/.zshrc

tip:

手动切换shell 输入shell名称

bash

zsh

执行上次使用的命令

!!

搜索历史执行命令

快捷键ctrl + r

就会进入对应的shell

配置主题

修改~/.zshrc中的环境变量ZSH_THEME

vim ~/.zshrc

ZSH_THEME=”agnoster” # (this is one of the fancy ones)

ZSH_THEME=”random” # (…please let it be pie… please be some pie..)

查看官网主题
https://github.com/robbyrussell/oh-my-zsh/wiki/Themes

配置插件

修改~/.zshrcplugins

plugins=(git bundler osx rake ruby)

安装自动补全插件

cd ~/.oh-my-zsh/custom/plugins/

git clone https://github.com/zsh-users/zsh-autosuggestions

source ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh

安装高亮

cd ~/.oh-my-zsh/custom/plugins/

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git

source ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
cd ~/.oh-my-zsh/custom/plugins/

git clone https://github.com/zsh-users/zsh-completions ${ZSH_CUSTOM:=~/.oh-my-zsh/custom}/plugins/zsh-completions

更新oh-my-zsh’

disable_update_prompt = true

禁用自动升级, 修改~/.zshrc

disable_auto_update = true

立即升级

upgrade_oh_my_zsh

卸载

uninstall_oh_my_zsh zsh

兼容 bash,原来使用 bash 的兄弟切换过来毫无压力,该咋用咋用。

强大的历史纪录功能,输入 grep 然后用上下箭头可以翻阅你执行的所有 grep 命令。

智能拼写纠正,输入gtep mactalk * -R,系统会提示:zsh: correct ‘gtep’ to ‘grep’ [nyae]? 比妹纸贴心吧,她们向来都是让你猜的……

各种补全:路径补全、命令补全,命令参数补全,插件内容补全等等。触发补全只需要按一下或两下 tab 键,补全项可以使用 ctrl+n/p/f/b上下左右切换。比如你想杀掉 java 的进程,只需要输入 kill java + tab键,如果只有一个 java 进程,zsh 会自动替换为进程的 pid,如果有多个则会出现选择项供你选择。ssh + 空格 + 两个tab键,zsh会列出所有访问过的主机和用户名进行补全

智能跳转,安装了autojump之后,zsh 会自动记录你访问过的目录,通过 j + 目录名 可以直接进行目录跳转,而且目录名支持模糊匹配和自动补全,例如你访问过hadoop-1.0.0目录,输入j hado 即可正确跳转。j –stat 可以看你的历史路径库。

目录浏览和跳转:输入 d,即可列出你在这个会话里访问的目录列表,输入列表前的序号,即可直接跳转。

在当前目录下输入 .. 或 … ,或直接输入当前目录名都可以跳转,你甚至不再需要输入 cd 命令了。

通配符搜索:ls -l */.sh,可以递归显示当前目录下的 shell 文件,文件少时可以代替 find,文件太多就歇菜了。

更强的别名

插件支持

本文总阅读量