1675

Windows10 git-bash 安装 zsh 和 oh_my_zsh 或 prezto

安装git-bash for windows

https://gitforwindows.org/
下载安装一直下一步即可

下载zsh

https://dotatong.cn/tools/zsh-5.8-3-x86_64.pkg.tar

下载后解压到 Git 安装的根目录,相当于对git bash做一个补充包。

安装oh_my_zsh

安装oh_my_zsh(MacOS也可使用该步骤安装oh_my_zsh)

sh -c "$(curl -fsSL https://dotatong.cn/tools/oh_my_zsh.sh)"

配置默认启动zsh

修改~/.bashrc,加上如下内容

# 启动zsh
if [ -t 1 ]; then
    exec zsh
fi

或者在 C:\Program Files\etc\bash.bashrc 文件中开头增加以下内容,可避免bash执行一些不必要的检查等,以加快zsh启动速度

# 启动zsh
if [ -t 1 ]; then
    exec zsh
    exit 0
fi

至此,配置完成,新建git bash就自动启动zsh了。

主题推荐使用 ys

ZSH_THEME="ys"

推荐主题

2022.11.16更新

基于refined自定义了一个类似ys的主题dotatong.zsh-theme,该主题不会导致窗口无响应。
下载 https://dotatong.cn/tools/dotatong.zsh-theme 该主题文件放至~/.oh-my-zsh/themes/目录

修改配置文件~/.zshrc

ZSH_THEME="dotatong"

oh_my_zsh替代方案Prezto

2022.11.09更新

以下主题,windows下不会导致窗口无响应

trapd00r , apple , rkj , mikeh , duellj , jtriley , linuxonly , cypher , refined

windows平台ohmyzsh部分主题,WindowsTerminal或者Webstorm/Phpstorm/Goland等jetbrain全家桶,内置终端替换为git-bash时。如果窗口大小改变会导致使用了ohmyzsh的git-bash窗口停止响应,无法再输入任何内容,必须重开终端才能继续使用!!!而MacOS下的zsh没有这个问题。

故替代方案,使用prezto,好用程度堪比ohmyzsh。窗口改变尺寸后不会停止响应,这点无可挑剔。

接下来开始安装,首先进入用户目录

cd ~

拉取prezto以及子模块,递归克隆,--recursive必须

git clone --recursive https://github.com/sorin-ionescu/prezto.git

创建初始化脚本 ~/test.sh

#!/bin/zsh
setopt EXTENDED_GLOB
for rcfile in "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/^README.md(.N); do
  ln -s "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile:t}"
done

删除~/.zsh*相关文件,然后执行~/test.sh

下载主题文件放至~/.zprezto/modules/prompt/functions/
https://dotanet.cn/tools/prompt_tong_setup

修改配置文件~/.zpreztorc

  • 键位风格
zstyle ':prezto:module:editor' key-bindings 'vi'
  • prezto主题
zstyle ':prezto:module:prompt' theme 'tong'
  • 自定义alias
alias gst='git status'
alias gco='git checkout'
alias gl='git pull'
alias gp='git push'
alias ga='git add *'
alias gm='git merge --no-ff'
alias gcm='git commit -m'
文章作者:DOTATONG
发布日期:2022-07-12

评论

暂无

添加新评论