Zsh 配置使用指南
Where there is a shell, there is a way.
Z shell(Zsh)是一款可用作交互式(英语:interactive)登录的shell及脚本编写的命令解释器。Zsh对Bourne shell做出了大量改进,同时加入了Bash、ksh及tcsh的某些功能。
自2019年起,macOS的预设Shell已从Bash改为Zsh。
zsh
Zsh is a shell designed for interactive use, although it is also a powerful scripting language.
全局配置 /etc/zshrc
当前用户配置文件 ~/.zshrc
|
|
Xcode Command Line Tools
从 App Store 上下载的 Xcode,默认是不会安装 Command Line Tools 的,Command Line Tools 是在 Xcode 中的一款命令行开发工具,gcc/g++编译器、make、git 等,是很多其他软件的基础。
xcode-select --install
安装完成后,在终端中执行 gcc -v
命令查看是否安装成功。
Homebrew 会自动安装 Command Line Tools。
|
|
Homebrew
The Missing Package Manager for macOS
Homebrew macOS 包管理工具,官方称之为缺失的软件包的管理器
与 Homebrew 搭配最常用的是 Homebrew-Cask ,它有点类似于一个开源的 App Store。
Homebrew只能用于安装命令行软件,不能用于安装带图形界面的软件。Homebrew-Cask是Homebrew的 一个扩展,可以用于安装带图形界面软件
|
|
此脚本将 Homebrew 安装到其首选前缀(/usr/local
对于 macOS Intel、/opt/homebrew
对于 Apple Silicon 和 /home/linuxbrew/.linuxbrew
对于 Linux),因此您使用 brew install 不需要 sudo
。
|
|
brew services
管理后台服务,可以简化 lauchctl
的操作。
macOS 使用 launchctl
命令加载开机自动运行的服务。
|
|
安装 Nerd Fonts
Nerd Fonts是一个使用大量字形(glyphs)(图标 icons)修补开发人员目标字体的项目。特别是从流行的 “标志性字体” 中添加大量额外的字形,例如 Font Awesome、Devions、Octicons 等。 如果不安装图形字体,终端中的图标就无法显示正确的字形。
|
|
iTerm 2
iTerm2 is a terminal emulator for macOs that does amazing things
|
|
- 打开iTerm2 右上角菜单:
iTerm2
—Make iTerm2 Default Term
- 配置全局热键显示/隐藏 iTerm2
iTerm2
-Preferences...
-Keys
- 勾选Hotkey
下的Show/hide iTerm2 with a system-wide hotkey
,将热键设置option + Space
- 修改配色方案
iTerm2
-Preferences...
-Profiles
-Colors
-Color Presets...
-Solarized Dark
- 应用字体到 iTerm2,
iTerm2 > Preferences > Profiles > Text > Font
选择Caskaydia Cove Nerd Font Complete Mono
|
|
Oh My Zsh
Oh My Zsh Unleash your terminal like never before.
|
|
|
|
Alias | Command |
---|---|
md | mkdir -p |
rd | rmdir |
.. | cd .. |
… | cd ../.. |
…. | cd ../../.. |
/ | cd / |
d | dirs -v (lists last visited directories) |
cd +n | Switch to directory number n |
- | cd to last visited directory |
1 | cd -1 |
2 | cd -2 |
3 | cd -3 (1~9) |
port-listen | lsof -i -P |
x | extract |
插件
~/.oh-my-zsh/plugins
官方插件目录~/.oh-my-zsh/custom/plugins
第三方插件目录$ZSH_CUSTOM/plugins
plugins=(vi-mode git z extract pyenv)
vi-mode
vi 模式 快速移动命令行光标
ESC to enter Normal mode.
- History
- ctrl-p : Previous command in history
- ctrl-n : Next command in history
- Movement
- $ : To the end of the line
- ^ : To the first non-blank character of the line
- 0 : To the first character of the line
- w : [count] words forward
- W : [count] WORDS forward
- e : Forward to the end of word [count] inclusive
- E : Forward to the end of WORD [count] inclusive
- b : [count] words backward
- B : [count] WORDS backward
- Insertion
- i : Insert text before the cursor
- I : Insert text before the first character in the line
- a : Append text after the cursor
- A : Append text at the end of the line
- Delete and Insert
- ctrl-h : While in Insert mode: delete character before the cursor
- ctrl-w : While in Insert mode: delete word before the cursor
- dd : Delete line
- D : Delete characters under the cursor until the end of the line
git
插件主要是一些 git 命令的 aliases
Alias | Command |
---|---|
ga | git add |
gb | git branch |
gba | git branch -a |
gbd | git branch -d |
gcam | git commit -a -m |
gcb | git checkout -b |
gcl | git clone –recurse-submodules |
gcmsg | git commit -m |
gco | git checkout |
gcp | git cherry-pick |
gd | git diff |
glol | git log –graph –pretty=’%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' |
glols | git log –graph –pretty=’%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset’ –stat |
glola | git log –graph –pretty=’%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset’ –all |
z
快速的切换文件路径。跟踪你最常访问的目录,并允许你用很少的按键来访问它们。
访问过 ~/.oh-my-zsh/plugins
|
|
extract
这个插件定义了一个函数,叫做extract提取你传递给它的存档文件,它支持各种各样的存档文件类型。
alias 是 x 用来解压文件。当然 tar -
加 tab
键,zsh 会列出参数的含义
支持 7z、apk、gz、ipa、jar、rar、tar、tar.gz、tgz、zip 等常见归档及压缩格式。
zsh 插件
以下这三个个插件可以使用 Homebrew 安装,这里以 Oh My Zsh 插件的形式安装。
- zsh-autosuggestions
- zsh-completions 命令自动补全 键盘 →
- zsh-syntax-highlighting 终端命令语法高亮
|
|
如果觉得键盘按键 → (苹果键盘在最右下角很便利)不方便,可自定义补全快捷键:
bindkey ',' autosuggest-accept
|
|
plugins=(
# other plugins...
zsh-autosuggestions
zsh-syntax-highlighting
)
fpath+=${ZSH_CUSTOM:-${ZSH:-~/.oh-my-zsh}/custom}/plugins/zsh-completions/src
# 追加 FPATH 在这条 source 命令前
source "$ZSH/oh-my-zsh.sh"
|
|
Powerlevel10k
Powerlevel10k is a theme for Zsh. It emphasizes speed, flexibility and out-of-the-box experience.
|
|
bat
Bat 命令是 cat 命令的克隆,具有许多吸引人且有用的功能。 其中一些功能是语法高亮、自动分页、git 集成等,也增强了程序员的体验。 👍
|
|
shell 中的色彩
|
|
SpaceVim
SpaceVim 是一个社区驱动的模块化 Vim IDE,以模块的方式组织管理插件以及相关配置, 为不同的语言开发量身定制了相关的开发模块,该模块提供代码自动补全, 语法检查、格式化、调试、REPL 等特性。
|
|
Quick Look plugin
|
|