引言
自macOS Catalina起, zsh 已取代 bash 成为新版操作系统中的默认 shell 。既然有这个条件, 不如试试更优雅的命令行输入吧.
Oh My Zsh是一个基于zsh命令行,提供了主题配置,插件机制,并内置了许多便捷操作的命令行输入工具。正如Oh My Zsh官网描述的Unleash your terminal like never before., 他确实给我带来了全新的输入体验.
其中最另我不能脱离的功能有二.
- 根据历史记录自动补全
- 不用
cd直接进入文件夹
Oh My Zsh is a delightful, open source, community-driven framework for managing your Zsh configuration. It comes bundled with thousands of helpful functions, helpers, plugins, themes, and a few things that make you shout...
效果展示
过程
下载
首先用zsh --version检查zsh是否存在以及已安装版本.
如不存在, 可以根据平台自行选择安装版本, 具体参考知乎zsh 安装与配置:9步打造高效命令行.
需要注意的是, Oh-My-ZSH需要v4.3.9及其以上.
如满足安装要求, 可使用curl, wget或fetch等工具下载.
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"如运行失败考虑是网络环境不好, 自行解决.
插件
插件的安装使用有两种方法, 一种是启用官方插件目录中的插件, 一种是手动启用.
oh-my-zsh 的自带插件都储存在~/.oh-my-zsh/plugins目录中,如果希望使用一个自带插件,可以在~/.zshrc的plugins=(xxx, xxx, ...)这一行里加入插件名称.
当插件不包含在官方库中时, 可以自行下载并启用, 以zsh-autosuggestions: zsh-autosuggestions - github为例.
zsh-syntax-highlighting 是一个命令语法校验插件,在输入命令的过程中,若指令不合法,则指令显示为红色,若指令合法就会显示为绿色。效果如下:
Oh My Zsh
- Clone this repository into
$ZSH_CUSTOM/plugins(by default~/.oh-my-zsh/custom/plugins)
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions- Add the plugin to the list of plugins for Oh My Zsh to load (inside
~/.zshrc):
plugins=(
# other plugins...
zsh-autosuggestions
)- Start a new terminal session.
Manual (Git Clone)
- Clone this repository somewhere on your machine. This guide will assume
~/.zsh/zsh-autosuggestions.
# zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-autosuggestions ~/.zsh/zsh-autosuggestions
# zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ~/.zsh/zsh-syntax-highlighting- Add the following to your
.zshrc:
# zsh-autosuggestions
source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh
# zsh-syntax-highlighting
source ~/.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh- Start a new terminal session.
另外, Homebrew可提供了一些插件的下载, 如:
# Homebrew
brew install zsh-syntax-highlighting之后同样source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh.
主题
Oh My Zsh支持许多主题的设置, 编辑 ~/.zshrc 文件即可体验.
官方提供了许多默认主题, 可以在oh-my-zsh 的 Wiki查看截图, 并在~/.zshrc中更改ZSH_THEME="xxx"更换. 如使用alanpeabody主题就是ZSH_THEME="alanpeabody".
Mac终端中文乱码修复
详见Mac终端使用oh-my-zsh中文乱码.
代码语言:shell复制# 更改
vim ~/.zshrc
# 更改后
source ~/.zshrc更改内容:
代码语言:shell复制export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8ubuntu安装
需要提前安装zsh, 其他与MacOS一致.
# apt安装软件
sudo apt-get install zsh
# 查看系统可以用的 shell
cat /etc/shells
# 使用命令将 zsh 设置为系统默认 shell
chsh -s /bin/zsh参考
- GitHub - ohmyzsh/ohmyzsh
- 打造一个简单好看实用的终端:Oh-My-Zsh 安装,配置以及设置终端代理


