[TOC]
安装
- 官网:https://ohmyz.sh/
- 国内镜像
1
2sudo apt install zsh
sh -c "$(wget https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh -O -)"
切换
- 切换bash:
chsh -s /bin/bash
- 切换zsh:
chsh -s /bin/zsh
- 需要系统注销,重新登录
配置
主题:https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
1
2vim ~/.zshrc
ZSH_THEME="主题名"编辑文件:
vim ~/.zshrc
1
2
3
4
5
6
7
8
9
10plugins=(
git
zsh-autosuggestions
zsh-syntax-highlighting
zsh-history-substring-search
vscode
sudo
autojump
z
extract)插件详细安装及解释
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34# Zsh命令自动补全插件 zsh-autosuggestions【tab 补全】
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
# Zsh命令语法高亮插件 zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
# zsh-history-substring-search【自动记住曾经使用过的历史命令用于以后作命令提示】
git clone https://github.com/zsh-users/zsh-history-substring-search ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-history-substring-search
# vscode【vs 文件路径】
git clone https://github.com/valentinocossar/vscode.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/vscode
# sudo【需要加sudo,按两下ESC】
# autojump【省去多次cd,直接跳转目录:j + 目录名】
sudo apt-get install autojump
# z【是oh-my-zsh默认就装好的,需要自己开启,功能同autojump】
# extract【所有的压缩文件,都可以直接x filename,真香】
# bat【相比 cat 增加了行号和颜色高亮】
# https://github.com/sharkdp/bat
# https://github.com/sharkdp/bat/releases 根据系统,下载最新版
wget https://github.com/sharkdp/bat/releases/download/v0.18.2/bat_0.18.2_amd64.deb
sudo dpkg -i bat_0.18.2_amd64.deb
# 自动补全插件 incr
# https://mimosa-pudica.net/zsh-incremental.html
cd .oh-my-zsh/plugins/
mkdir incr # 将下载的文件放到incr里 incr-0.2.zsh
vim ~/.zshrc
# 添加 source ~/.oh-my-zsh/plugins/incr/incr*.zsh
source ~/.zshrc刷新:
source ~/.zshrc
z命令使用
- 只有你访问过的路径才会被记录
1
2
3
4
5
6
7
8
9
10
11# 显示记录的路径
z
# 切换到一个名字带有 "foo" 的路径
z foo
# 切换到一个名字带有 "foo" 并且后面带有 "bar" 的路径(例:fooesbar):
z foo bar
# 列出在 z 的数据库中名字带有 "foo" 的路径
z -l foo
其他技巧
- 搜索历史命令:
ctrl + r
- 命令别名:
1
2
3
4vim .zshrc
# alias 简短命令='原始命令'
gcb='git checkout -b'
# 查看有哪些别名:alias