基于 gitbash 的 zsh-windows 使用

安装必要软件

我使用 Windows Terminal , 配合 Git-Bash 可以在 Windows 中使用 zsh,芜湖

Git For Windows

这个不用多说

zsh

MSYS2 Packages 页面 中下载 zsh

将压缩包中的 etcusr 文件夹移动到 git-bash.exe 所在文件夹

配置

在用户目录下的 .bashrc 文件中写入

1
2
3
if [ -t 1 ]; then
exec `zsh`
fi

用于切换 shell 至 zsh

然后重启 gitbash 就会切换至 zsh

在 MSYS2 中使用安装在 Program Files 目录下的 starship 时遇到一些权限问题,最后是通过在 gitbash 中使用 ln 创建硬链接解决了,不要使用 mklink,这和 MSYS2 不兼容

1
ln "/c/Real/Path/starship.exe" "/c/APP/Bin/starship.exe"

之后就是跟着 zsh 指导完成新手配置,一下是我的配置

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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# alias
alias nv="nvim"

# Lines configured by zsh-newuser-install
HISTFILE=~/.histfile
HISTSIZE=1000
SAVEHIST=1000
# End of lines configured by zsh-newuser-install
# The following lines were added by compinstall
zstyle :compinstall filename '/c/Users/32663/.zshrc'

autoload -Uz compinit
compinit
# End of lines added by compinstall

# Key
WORDCHARS='*?_-.[]~=&;!#$%^(){}<>'

# 上下键子串历史
bindkey '^[[A' history-substring-search-up
bindkey '^[[B' history-substring-search-down

## Ctrl + ← / → 按词移动
bindkey '^[[1;5D' backward-word
bindkey '^[[1;5C' forward-word
bindkey '^[Od' backward-word # 兼容
bindkey '^[Oc' forward-word

## Delete / Home / End
bindkey '^[[3~' delete-char
bindkey '^[[H' beginning-of-line
bindkey '^[[F' end-of-line
bindkey '^[[1~' beginning-of-line
bindkey '^[[4~' end-of-line

## Ctrl + Delete:删后一词
bindkey '^[[3;5~' kill-word

## Ctrl + Backspace:删前一词
bindkey '^H' backward-kill-word


# 插件
source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh
source ~/.zsh/zsh-history-substring-search/zsh-history-substring-search.zsh
source ~/.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
eval "$(zoxide init zsh)"
source <(fzf --zsh)

# starship
eval "$(starship init zsh)"