197

Win11 git-bash安装zsh和oh_my_zsh

安装git-bash for windows

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

下载zsh

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

下载后解压到 Git 安装的根目录(例如:C:\Program Files\Git),相当于对git bash做一个补充包。

安装oh_my_zsh

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

安装oh_my_zsh主题

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

修改配置文件~/.zshrc

ZSH_THEME="dotatong"

配置环境变量

在系统环境变量的path中,加入该路径

C:\Program Files\Git\usr\bin

作用是为了直接执行C:\Program Files\Git\usr\bin\zsh.exe时,能够利用该目录提供的linux常用工具,例如:mkdir、rm、chmod等等

直接使用zsh

之前的方案是在~/.bashrc中加入切换到zsh的命令,来启用zsh和oh_my_zsh,该方式有时候启动速度比较慢。所以我们采用直接执行
C:\Program Files\Git\usr\bin\zsh.exe的方式启用zsh。

具体做法:

  1. Windows Terminal Preview中的Git Bash的启动命令修改为C:\Program Files\Git\usr\bin\zsh.exe
  2. 将IDE中的terminal启动命令修改为C:\Program Files\Git\usr\bin\zsh.exe

Windows Terminal Preview配置

建议:推荐安装Windows Terminal Preview,因为该版本,窗口未激活状态也能保持透明度。

这里贴出我的终端配置

{
    "$help": "https://aka.ms/terminal-documentation",
    "$schema": "https://aka.ms/terminal-profiles-schema-preview",
    "actions": 
    [
        {
            "command": 
            {
                "action": "copy",
                "singleLine": false
            },
            "id": "User.copy.644BA8F2",
            "keys": "ctrl+c"
        },
        {
            "command": 
            {
                "action": "globalSummon"
            },
            "id": "User.globalSummon.51A3D78C",
            "keys": "ctrl+alt+e"
        },
        {
            "command": 
            {
                "action": "switchToTab",
                "index": 0
            },
            "id": "User.switchToTab.D3F0B923",
            "keys": "ctrl+1"
        },
        {
            "command": "unbound",
            "keys": "ctrl+shift+t"
        },
        {
            "command": "unbound",
            "keys": "ctrl+shift+n"
        },
        {
            "command": "unbound",
            "keys": "ctrl+shift+w"
        },
        {
            "command": "unbound",
            "keys": "win+sc(41)"
        },
        {
            "command": "unbound",
            "keys": "f12"
        },
        {
            "command": "unbound",
            "keys": "ctrl+alt+1"
        },
        {
            "command": "unbound",
            "keys": "ctrl+alt+2"
        },
        {
            "command": "unbound",
            "keys": "ctrl+alt+3"
        },
        {
            "command": "unbound",
            "keys": "ctrl+alt+4"
        },
        {
            "command": "unbound",
            "keys": "ctrl+alt+5"
        },
        {
            "command": 
            {
                "action": "switchToTab",
                "index": 4
            },
            "id": "User.switchToTab.F747588A",
            "keys": "ctrl+5"
        },
        {
            "command": "paste",
            "id": "User.paste",
            "keys": "ctrl+v"
        },
        {
            "command": 
            {
                "action": "switchToTab",
                "index": 3
            },
            "id": "User.switchToTab.6CD791B",
            "keys": "ctrl+4"
        },
        {
            "command": 
            {
                "action": "switchToTab",
                "index": 1
            },
            "id": "User.switchToTab.2A0DA8E0",
            "keys": "ctrl+2"
        },
        {
            "command": 
            {
                "action": "quakeMode"
            },
            "id": "User.quakeMode.F1E129A4"
        },
        {
            "command": 
            {
                "action": "newTab"
            },
            "id": "User.newTab.5DEADB41"
        },
        {
            "command": "find",
            "id": "User.find",
            "keys": "ctrl+shift+f"
        },
        {
            "command": 
            {
                "action": "splitPane",
                "split": "auto",
                "splitMode": "duplicate"
            },
            "id": "User.splitPane.A6751878",
            "keys": "alt+shift+d"
        },
        {
            "command": 
            {
                "action": "switchToTab",
                "index": 2
            },
            "id": "User.switchToTab.87C324ED",
            "keys": "ctrl+3"
        },
        {
            "command": 
            {
                "action": "newWindow"
            },
            "id": "User.newWindow.5DEADB41",
            "keys": "ctrl+n"
        },
        {
            "command": "closePane",
            "id": "User.closePane",
            "keys": "ctrl+w"
        },
        {
            "command": "duplicateTab",
            "id": "User.duplicateTab",
            "keys": "ctrl+t"
        }
    ],
    "copyFormatting": "none",
    "copyOnSelect": false,
    "defaultProfile": "{2ece5bfe-50ed-5f3a-ab87-5cd4baafed2b}",
    "newTabMenu": 
    [
        {
            "type": "remainingProfiles"
        }
    ],
    "profiles": 
    {
        "defaults": 
        {
            "colorScheme": "One Half Dark"
        },
        "list": 
        [
            {
                "commandline": "%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
                "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
                "hidden": false,
                "name": "Windows PowerShell"
            },
            {
                "commandline": "%SystemRoot%\\System32\\cmd.exe",
                "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
                "hidden": false,
                "name": "\u547d\u4ee4\u63d0\u793a\u7b26"
            },
            {
                "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
                "hidden": false,
                "name": "Azure Cloud Shell",
                "source": "Windows.Terminal.Azure"
            },
            {
                "backgroundImageOpacity": 0.3,
                "commandline": "C:/Program Files/Git/usr/bin/zsh.exe",
                "font": 
                {
                    "face": "Consolas",
                    "size": 12
                },
                "guid": "{2ece5bfe-50ed-5f3a-ab87-5cd4baafed2b}",
                "hidden": false,
                "name": "Git Bash",
                "opacity": 80,
                "source": "Git",
                "useAcrylic": true
            }
        ]
    },
    "schemes": [],
    "theme": "dark",
    "themes": []
}
文章作者:DOTATONG
发布日期:2024-07-10
# win11

评论

暂无

添加新评论