Linux:安装zsh、oh-my-zsh
一、zsh概述
1、zsh是什么
一个及其好用的类Linux系统中的终端软件,江湖称之为马车中的跑车,跑车中的飞行车,史称『终极 Shell』。 可在linux unix及 MAC OS上运行,借助Msys2 等也可以运行在window中。
2、zsh常用快捷键
- CTRL + A
: 移动到行(line)的开始位置~~ - CTRL + E
: 移动到行的最后面~~ - CTRL + [left arrow]
: 向后移动一个单词(one word)~~ - CTRL + [right arrow]
: 向前移动一个单词~~ - CTRL + U/Q
: 将整行清除~~ - ESC + [backspack]
: 删除光标前面的单词 - CTRL + W
: 同上~~ - CTRL + D
: 删除光标后面的字符 - CTRL + R
: 搜索历史 - CTRL + _
: 撤销最后一次的改变 - CTRL + L
: 清空屏幕 - CTRL + S
: 停止向屏幕继续输出 - !!
: 执行历史记录中的上一个命令 - !abc
: 打印历史记录中的以 abc开头的命令 - 命令r 可自动执行上一条命令
- 命令!!可以回溯上一次的命令。
dirs -v 查看历史访问目录
- d dirs -v的简写
- ~1 切换到第一个目录
autojump 只能让你跳到那些你已经用 cd 到过的目录
- jo dir 使用资源管理器打开指定dir
- j dir 打开 dir
3、常用zsh git的快捷键
g - git
gst - git status
gl - git pull
gup - git pull --rebase
gp - git push
gd - git diff
gdc - git diff --cached
gdv - git diff -w "$@" | view
gc - git commit -v
gc! - git commit -v --amend
gca - git commit -v -a
gca! - git commit -v -a --amend
gcmsg - git commit -m
gco - git checkout
gcm - git checkout master
gr - git remote
grv - git remote -v
grmv - git remote rename
grrm - git remote remove
gsetr - git remote set-url
grup - git remote update
grbi - git rebase -i
grbc - git rebase --continue
grba - git rebase --abort
gb - git branch
gba - git branch -a
gcount - git shortlog -sn
gcl - git config --list
gcp - git cherry-pick
glg - git log --stat --max-count=10
glgg - git log --graph --max-count=10
glgga - git log --graph --decorate --all
glo - git log --oneline --decorate --color
glog - git log --oneline --decorate --color --graph
gss - git status -s
ga - git add
gm - git merge
grh - git reset HEAD
grhh - git reset HEAD --hard
gclean - git reset --hard && git clean -dfx
gwc - git whatchanged -p --abbrev-commit --pretty=medium
gsts - git stash show --text
gsta - git stash
gstp - git stash pop
gstd - git stash drop
ggpull - git pull origin $(current_branch)
ggpur - git pull --rebase origin $(current_branch)
ggpush - git push origin $(current_branch)
ggpnp - git pull origin $(current_branch) && git push origin $(current_branch)
glp - _git_log_prettily
zsh git的快捷命令 实现原理
实现原理 别名
alias gst='git status'
alias gp='git push'
alias gp='git push'
一、安装
1、zsh
# 先更新本地包
sudo apt-get update
# 安装zsh
sudo apt-get install zsh
# 设置zsh为默认shel, 设置->重启终端
chsh -s /bin/zsh
2、安装 oh-my-zsh
# 安装oh-my-zsh
wget https://files-cdn.cnblogs.com/files/hongdada/install.sh -O - | sh
如果 wget 安装 oh-my-zsh 多次还是失败,请本地安装:
# gitee版本-> 先克隆项目
git clone https://gitee.com/mirrors/oh-my-zsh.git
# 本地安装(安装完,重启终端)
sudo ./oh-my-zsh/tools/install.sh
更新 oh-my-zsh(尝试多次失败可直接跳过)
omz update
3、插件安装(感谢 一亩三分地 的 gitee)
# github原版 自动补全
sudo git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
# gitee版本
sudo git clone https://gitee.com/unrogue007/zsh-autosuggestions.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
# github原版 命令行语法高亮
sudo git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
# gitee版本
sudo git clone https://gitee.com/unrogue007/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
4、设置主题和字体(感谢 Moe (mo2) - Gitee.com 、17 (keyboardkiller) - Gitee.com)
# github原版 安装 Powerlevel10k 主题
sudo git clone https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/themes/powerlevel10k
# gitee版本
sudo git clone https://gitee.com/mo2/powerlevel10k.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/themes/powerlevel10k
gitee里下载hack字体:
双击下载后的字体安装:
5、修改vscode默认字体
settings.json,添加以下配置(主要看上图安装时候的字体名称,对应上即可):
"editor.fontFamily": "Hack NF"
保存后重启 vscode !这里重启 vscode。
6、修改 .zshrc 配置,自定义 Powerlevel10k 样式
# 编辑配置
sudo vim ~/.zshrc
###################################################### 替换plugins=(git) start
# 设置主题
ZSH_THEME="powerlevel10k/powerlevel10k"
# 启动错误命令自动更正
ENABLE_CORRECTION="true"
# 在命令执行的过程中,使用小红点进行提示
COMPLETION_WAITING_DOTS="true"
# 不展示初始提示
ZSH_DISABLE_COMPFIX="true"
# 启用已安装的插件
plugins=(
git zsh-autosuggestions zsh-syntax-highlighting
)
###################################################### 替换plugins=(git) end
# 生效配置(没有提示,说明之前安装过,可以重新修改)
source ~/.zshrc
# 重新修改 Powerlevel10k 样式
p10k configure
===================== 后续设置自己定制 =======================
7、其他
# 更新
upgrade_oh_my_zsh
# 卸载 Oh My Zsh
uninstall_oh_my_zsh
终端利器zsh快速入门 - 知乎
还没有评论,来说两句吧...