记录下win 11 git bash 安装on my zsh(亲测有效⛄,vscode 和 window terminal 使用)

2,750 阅读3分钟

# 记录下win 11 git bash 安装on my zsh(亲测有效⛄,vscode 和 window terminal 使用)

话不多说,直接上号!!!⚡

image.png

效果展示

window terminal 终端:

image.png VScode 终端:

image-20220628133617509

步骤

image.png

  1. 首先,大家电脑安装都了window terminal 和git bash ,git bash 作为默认终端吧!!

image.png

2 为git bash 安装zsh

image.png

  • 通过7-zip-zstd 进行解压,图中两个随便下一个。

image.png

  • 通过z-zip讲解压文件直接解压到GIt 安装目录的根目录,不知道目录的话,直接在git bash 命令行 查询 where git

image.png

  • 解压后,git 安装根目录如下图所示

  • 打开 window terminal (默认也就是git bash ) 输入zsh 一般会出现如下所示,因为没截图,下面这张图来自网csdn上作者 啦啦啦小石头

  • (如有侵权,请联系我删哈,多有打扰😊)

image.png

  1. 安装字体(非必可),我用默认主题,就没用安装其他字体,其他主题的话,可能需要去powerline安装对于字体,大家自行百度哈!

这个字体,大家随便下,下好后,打开压缩包,右键直接可以安装,安装完成后再如下图所示配置,或者setting.json文件配置都行。

  1. 安装on my zsh 官网

复制如下命令安装,如果你能安装成功的话就直接安装。反正我电脑不行,科学上网也不行。

shc" sh -c "(curl -fsSL raw.github.com/ohmyzsh/ohm…)"

通过下载下拉方式安装,下载链接就是官网的链接,image-20220628221909281

方便大家,下载链接在这

下载再本地目录后,通过 sh install.sh 安装on my zsh ,安装完成后,再git bash 输入zsh 就会进入到熟悉的zsh了。

image.png

  1. 为on my zsh 配置主题和插件,

1 进入on my zsh插件文件夹

cd ~/.oh-my-zsh/custom/plugins

下载 zsh-autosuggestions(输入命令时可提示自动补全(灰色部分),然后按键盘 → )和zsh-syntax-highlighting(日常用的命令会高亮显示,命令错误显示红色)两个插件,

接着vim ~/.zshrc 修改plugins 行

plugins=(git zsh-autosuggestions zsh-syntax-highlighting)

zai

理想情况下安装插件后会如下图所示

image.png

如果出现问题呢

image.png

其实还有另外一种解决方法🐼

image.png

找到自己安装插件的位置,在plugins行下面添加如下行,这是我电脑安装插件的路径

source $HOME/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

source $HOME/.oh-my-zsh/custom/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh

PS:$HOME为用户根目录,也就是你主机目录,后面就是插件安装位置

image.png

再次在git bash 中更新zsh

source ~/.zshrc

  1. 讲zsh终端配置为默认git bash 启动终端

    打卡你git 安装根目录找到这个文件 E:\Program Files\Git\etc\bash.bashrc(比如这里我git安装在E盘)

    将以下命令添加到末尾

    # Launch Zsh
    if [ -t 1 ]; then
    exec zsh
    fi
    
  2. 重启终端,就会发现git bash 自动进入到zsh了,这里这个方法判断再进入zhs 终端,初次启动会有1~2 s延迟,stack overflow上也有人讨论这个问题,可以看看这篇git bash,stack overflow 。

配置git bash 到vscode

打开设置,settings.json,在末尾添加配置终端

"terminal.integrated.profiles.windows": {

"PowerShell -NoProfile": {

"source": "PowerShell",

"args": ["-NoProfile"]

},

"Git-Bash": {

"path": "E:\program file\Git\bin\bash.exe", # 本地安装的路径

"args": []

}

},

"terminal.integrated.defaultProfile.windows": "Git-Bash"

再把git bash 设置为vscode 默认终端,就欧克啦。走啦走啦!🐱‍🚀

image.png

总结

  1. git bash 配置zsh 启动时候会有明显的1~2 s 的延迟。

参考文章

Install Terminal + git-bash + zsh + oh-my-zsh on Windows 10

在git bash中使用oh my zsh

一文搞定 Windows Terminal 设置与 zsh 安装【非WSL】

windows下修改vscode默认终端为git bash