My Zsh Config
My personal config for Zsh (Z Shell), noting for next time.
Installation
Windows
Native GNU bash doesn't run on windows, but you can use something like git bash (msys2) to run bash on windows. Furthermore, you can also use zsh on windows. The articles below may be helpful:
The default character set used on your Windows platform may not be UTF-8. You can add these lines to your ~/.zshrc
to enable UTF-8 in your terminal:
1 | # Set Windows codepage to 65001 (UTF-8). |
You may also need a terminal emulator on windows. I use alacritty and my config file looks like:
1 | working_directory = "C:\\Users\\BlockLune" |
Linux
Use your favorite package manager to install zsh
and then run chsh -s $(which zsh)
to set Z Shell as your default shell.
Mac
It's installed by default.
Themes and Plugins
Firstly, install oh-my-zsh and powerlevel10k.
1 | # installs oh-my-zsh using curl |
Then, to set powerlevel10k
as the theme, edit in ~/.zshrc
:
1 | ZSH_THEME="powerlevel10k/powerlevel10k" |
Plugins
Oh-my-zsh provides many plugins (See the list), and you can install more by yourself.
I installed some plugins not provided by oh-my-zsh:
1 | # git clone https://github.com/esc/conda-zsh-completion ${ZSH_CUSTOM:=~/.oh-my-zsh/custom}/plugins/conda-zsh-completion |
Edit in ~/.zshrc
:
1 | # I disable some plugins here |
Usage of some plugins:
git
: GitHub
Alias | Command |
---|---|
g | git |
ga | git add |
gaa | git add --all |
gapa | git add --patch |
gau | git add --update |
gav | git add --verbose |
gb | git branch |
gco | git checkout |
gcl | git clone --recurse-submodules |
gcam | git commit --all --message |
gc | git commit --verbose |
gc! | git commit --verbose --amend |
gd | git diff |
gf | git fetch |
glog | git log --oneline --decorate --graph |
gl | git pull |
gp | git push |
gst | git status |
gss | git status --short |
... | ... |
git-commit
: GitHub
Syntax: git <type> [(-s, --scope) "<scope>"] "<message>"
, where <type>
is:
build
chore
ci
docs
feat
fix
perf
refactor
rev
style
test
NOTE: the alias for revert
type is rev
, as otherwise it conflicts with the git command of the same name.
It will still generate a commit message in the format revert: <message>
Alias | Command |
---|---|
git style "remove trailing whitespace" | git commit -m "style: remove trailing whitespace" |
git fix -s "router" "correct redirect link" | git commit -m "fix(router): correct redirect link" |
Aliases
Actually, the two plugins shown above (git & git-commit) are some aliases. A better practice is to define them yourself, so that they are more useful to you. First create a file ~/.zsh_aliases
and define your aliases:
1 | # .bash_aliases |
Then, source the file in your ~/.zshrc
:
1 | [[ -f ~/.zsh_aliases ]] && source ~/.zsh_aliases |
Lazyload
As your configuration increases, the terminal may take longer to start. In this case, some lazyload configurations shown in the article below may be helpful: