Mac下使用Oh-My-Zsh命令行插件

原创
2019/06/24 00:59
阅读数 3.8K

[TOC]

Mac下使用Oh-My-Zsh命令行插件

安装HomeBrew

依赖
Xcode Commend Line

如果此时你还没有安装homebrew的话,安装homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

安装 iTerm2

命令行插件不是说,只有iterm2才提示的,Mac自带的terminal.
只是说我喜欢用iterms2而已

一般我都是直接去这里下载:
https://www.iterm2.com

命令行运行:
brew install iterm2

安装 Oh-My-Zsh

安装
命令行运行:

sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
卸载的时候调用uninstall.sh即可
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/uninstall.sh)"

主题和字符

更改主体:
vim ~/.zshrc
# 一般我都用这个amuse主体,会显示当前分支和命令执行时间.
ZSH_THEME="amuse"
# 或者这些主题也不错(都是官方的,只管配置不需要安装插件)
ZSH_THEME="amuse"
ZSH_THEME="ys"
ZSH_THEME="avit"
ZSH_THEME="awesomepanda"
ZSH_THEME="bureau"
ZSH_THEME="agnoster"
ZSH_THEME="mortalscumbag"

# 需要的话,也可可以在安装一下Powerline,在窗口下面显示当前网络和系统性能
https://github.com/powerline/powerline


解决路径中字体混乱:
# 下载
git clone https://github.com/powerline/fonts.git

# 安装 如果要卸载,当前目录下有uninstall.sh 给755权限后即可执行
cd fonts
./install.sh

# 删除安装包
cd ..
rm -rf fonts

# 最后然后打开Items2-->Preferences-->Profiles-->Text-->Font选中power结尾的字体即可
# 记住选择的时候看列表里面带*的才是启用的,默认是default

配置

官方插件

# 添加插件(不要太多要不然加载起来会很慢)
vim ~/.zshrc

# 多个插件按空格分开,这里的git自动补全git branch 时会进入一个类似linux中more命令的界面,需要q退出.
# git               该插件添加了许多别名 https://github.com/robbyrussell/oh-my-zsh/wiki/Plugin:git
# command-not-found 命令不存在的时候, 使用相关命令建议包名
# autojump          扩展到频繁使用的目录,具体查看 autojump --help
# redis-cli         Redis命令自动补全
# screen            是screen的界面更加丰富
# cp                带进度条的复制
# colorize          cat出来的东西带语法高亮显示支持
# vi-mode         vim扩展
# git-open        在浏览器打开当前项目地址
plugins=(git command-not-found autojump redis-cli screen cp colorize vi-mode git-open)

# 如果需要在当前shell中生效
source ~/.zshrc

# 官方插件一览表
https://github.com/robbyrussell/oh-my-zsh/wiki/Plugins-Overview

第三方插件

  • 命令行语法高亮和历史命令的自动提示

历史命令的自动提示,会在命令后面显示之前的输入,按方向键右键或control+e即可全部补全.想改就改,不想改就全当是提示了.

Mac使用brew安装(支持电脑内所有的命令行工具)

# Mac安装高亮插件和自动提示插件
brew install zsh-syntax-highlighting
brew install zsh-autosuggestions

# 将安装完毕的提示写入`~/.zshrc`
echo 'source /usr/local/share/zsh-autosuggestions/zsh-autosuggestions.zsh' >> ~/.zshrc
echo 'source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh' >> ~/.zshrc

其他方式(仅支持zsh下提示)

# 下载到zsh的自定义扩展目录
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

# 然后在~/.zshrc的plugins中添加支持
plugins=( [plugins...] zsh-syntax-highlighting zsh-autosuggestions)
  • 非zsh插件

安装bash_completion.sh,该插件并非zsh扩展

# Mac下安装和激活,安装完之后会提示接下来会怎么部署脚本,每个版本貌似有所不同
brew install bash-completion
# Ubuntu下安装
apt install -y bash-completion
# 部署脚本
echo '[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"' >> ~/.zshrc

使用zsh替换bash

# 记住这个需要重启才能生效
$ chsh -s `which zsh`
# or
$ sudo usermod -s /bin/zsh username
展开阅读全文
加载中

作者的其它热门文章

打赏
0
0 收藏
分享
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部