目录

Windows Shell

Windows Terminal

Windows 终端是一个新式主机应用程序,它面向你喜爱的命令行 shell,如命令提示符、PowerShell 和 bash(通过适用于 Linux 的 Windows 子系统 (WSL))。 它的主要功能包括多个选项卡、窗格、Unicode 和 UTF-8 字符支持、GPU 加速文本呈现引擎,你还可用它来创建你自己的主题并自定义文本、颜色、背景和快捷方式。

可以通过命令面板调用 Windows 终端的大多数功能。 调用它的默认键组合是 Ctrl+Shift+P。

常用的快捷键

按键 效果
Alt + Enter 全屏
关闭窗口 Ctrl + D(需当前行没有字符才可用)
清屏 Ctrl + L
打开终端 右键快捷方式,在属性中自行设置
复制粘贴 Ctrl + Shift + C/V(v2.20.0 版本后才支持)

其他快捷键遵循 Bash 标准快捷键,例如 Ctrl + R 搜索历史命令、exit 退出终端、clear 和 reset 清屏、Ctrl + E/A 光标到行首尾,等等可自行搜索。

  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
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
{
  "defaultProfile": "{5db0cded-5450-45cc-a7e0-7eb2b455102f}",
  "profiles": 
    {
        "defaults": {},
        "list": 
        [
            {
                "colorScheme": "Solarized Dark",
                "commandline": "%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
                "font": 
                {
                    "size": 16
                },
                "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
                "hidden": false,
                "name": "Windows PowerShell",
                "opacity": 80,
                "useAcrylic": true
            },
            {
                "colorScheme": "Retro",
                "commandline": "%SystemRoot%\\System32\\cmd.exe /K chcp 65001 > nul",
                "cursorShape": "filledBox",
                "experimental.retroTerminalEffect": true,
                "font": 
                {
                    "size": 16
                },
                "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
                "hidden": false,
                "name": "\u547d\u4ee4\u63d0\u793a\u7b26",
                "useAcrylic": true
            },
            {
                "colorScheme": "AtomOneLight",
                "commandline": "C:\\Apps\\Git\\bin\\bash.exe -l -i",
                "cursorColor": "#FFFFFF",
                "cursorShape": "emptyBox",
                "font": 
                {
                    "face": "CaskaydiaCove Nerd Font Mono",
                    "size": 16
                },
                "guid": "{5db0cded-5450-45cc-a7e0-7eb2b455102f}",
                "hidden": false,
                "icon": "C:\\Apps\\Git\\mingw64\\share\\git\\git-for-windows.ico",
                "name": "Git Bash",
                "opacity": 75,
                "startingDirectory": "C:\\workspace",
                "useAcrylic": true
            }
        ]
    },
    "schemes": 
    [
        {
            "name": "AtomOneLight",
            "background": "#F9F9F9",
            "black": "#000000",
            "blue": "#2F5AF3",
            "brightBlack": "#BDBDBD",
            "brightBlue": "#727AF3",
            "brightCyan": "#78DCE8",
            "brightGreen": "#A9DC76",
            "brightPurple": "#BF86F2",
            "brightRed": "#FF6347",
            "brightWhite": "#FFFFFF",
            "brightYellow": "#FC9867",
            "cursorColor": "#757575",
            "cyan": "#2D7F95",
            "foreground": "#FF6188",
            "green": "#00FF00",
            "purple": "#950095",
            "red": "#FF2400",
            "selectionBackground": "#DBBBE0",
            "white": "#BBBBBB",
            "yellow": "#FFD866"
        },
        {
            "background": "#000000",
            "black": "#00FF00",
            "blue": "#00FF00",
            "brightBlack": "#00FF00",
            "brightBlue": "#00FF00",
            "brightCyan": "#00FF00",
            "brightGreen": "#00FF00",
            "brightPurple": "#00FF00",
            "brightRed": "#00FF00",
            "brightWhite": "#00FF00",
            "brightYellow": "#00FF00",
            "cursorColor": "#FFFFFF",
            "cyan": "#00FF00",
            "foreground": "#00FF00",
            "green": "#00FF00",
            "name": "Retro",
            "purple": "#00FF00",
            "red": "#00FF00",
            "selectionBackground": "#FFFFFF",
            "white": "#00FF00",
            "yellow": "#00FF00"
        }
    ]
}

终端字体 patched fonts

Powerline is a statusline plugin for vim,and provides statuslines and prompts for several other applications, including zsh, bash, tmux, IPython, Awesome and Qtile.

Windows 下 GNU

  • Cygwin 大量 GNU 和开源工具,它们提供类似于 Windows 上的 Linux 发行版 的功能。
  • MSYS2 是一组工具和库,为您提供易于使用的环境,用于构建、安装和运行本机 Windows 软件。它包括一个名为 mintty的命令行终端、bash、git 和 subversion 等版本控制系统、tar 和 awk 等工具,甚至 autotools 等构建系统,所有这些都基于Cygwin的修改版本。为了提供简单的软件包安装和保持更新的方法,它提供了一个名为 Pacman的软件包管理系统,Arch Linux 用户应该熟悉该系统。
  • Mingw-w64 是对原始 mingw.org 项目的改进,旨在支持 Windows 系统上的 GCC 编译器。为了提供对 64 位和新 API 的支持,它在 2007 年对其进行了分叉。从那时起,它得到了广泛的使用和分发。
  • Mingw(Minimalist GNU for Windows)

Git Bash

git bash 命令行默认使用 mintty 作为终端模拟器

安装 Git

下载 [Git for Windows]https://git-scm.com/download/win

安装 zsh

Package: zsh 将这些文件直接解压到 Git 的安装目录下,与之前的文件进行合并,可以理解为把 zsh 当作 git bash 的一个补充安装包。下载 zsh-xxx-x86_64.pkg.tar.zst

1
2
3
# 解压 unix 上比较容易
yum install zstd -y
tar -I zstd -xvf zsh-5.9-1-x86_64.pkg.tar.zst

覆盖 /etc /usr

启动 git bash

1
2
zsh
zsh --version

安装 Oh My Zsh

1
2
3
4
5
6
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
ls ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}
# 自动补全
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
# 语法高亮
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
1
2
3
4
5
plugins=(git z zsh-autosuggestions zsh-syntax-highlighting)
# 给 history 命令增加时间
HIST_STAMPS="mm/dd/yyyy"

source ~/.bashrc

配置 zsh 为 bash 默认终端

Git Bash 在 Win 端只会 source ~/.bash_profile 而不会激活 ~/.bashrc 的配置。所以如果你和我一样,喜欢在 ~/.bashrc 配置别名,在 ~/.bash_profile 配置环境的话,

解决方法是那就在 ~/.zshrc 加一行,source ~/.bashrc 就好啦!

1
code ~/.bash_profile
1
2
3
4
# Launch Zsh
if [ -t 1 ]; then
exec zsh
fi
1
vim ~/.bashrc
alias ll='ls -l'
# start = explorer.exe
alias open='explorer.exe'
alias tree='tree -FCN'
alias tree3='tree -L 3'
alias fuck='cowsay -f dragon Fuck You! | lolcat'

export PATH="/C/Users/Ethan/scoop/shims:$PATH"

function hosts {
    code C:/Windows/System32/drivers/etc/hosts
}
function desktop {
  # explorer.exe shell:RecycleBinFolder
  explorer.exe shell:desktop
}

配置 Windows Terminal 使用 git bash

使用快捷键 Ctrl + , 打开配置文件 settings.json。

在 profiles > list 下新增一个 object,加入 git bash。

commandline 为 git bash 的路径。

为了确保 .bash_profile 被加载,需要在 commandline 选项中加入 -l -i 。

icon 图标是下面这个,当然也可以换成你喜欢的。

/images/os/wsl/git-icon.png

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
"defaultProfile": "{1c4de342-38b7-51cf-b940-2309a097f589}"
{
    "guid": "{1c4de342-38b7-51cf-b940-2309a097f589}",
    "hidden": false,
    "name": "git bash",
    "commandline": "\"C:\\Program Files\\Git\\bin\\bash.exe\" -i -l",
    "historySize": 9001,
    "name": "Bash",
    "closeOnExit": true,
    "useAcrylic": true,
    "acrylicOpacity": 0.85,  //透明度
    "icon": "C:\\Apps\\Git\\mingw64\\share\\git\\git-for-windows.ico",
    "startingDirectory": null
}

powerlevel10k

推荐主题 powerlevel10k

p10k 在 Windows 上缺少字体,安装 Nerd Fonts,推荐 Caskaydia Cove Nerd Font 。

Windows Terminal 配置字体

1
2
# 配置主题
p10k configure

tree

下载 Binaries 下载解压完成后,将 bin 目录下的 tree.exe 复制到 Git Bash 安装路径下的 usr/bin 文件夹下。

常用命令

基本命令格式:tree [-option] [dir]

  • 显示中文,-N,如果中文名是中文,不加-N 有些电脑上是乱码的
  • 选择展示的层级:-L [n]
  • 只显示文件夹:-d
  • 区分文件夹、普通文件、执行文件:-FC,C 是加上颜色,
  • 起别名:可以起一个别名 alias tree=‘tree -FCN’
  • 输出目录结构到文件,写文档的时候需要展示项目目录就会用到 tree -L 2 -I '.js|node_modules|.md|.json|.css|*.ht' > tree.txt

scoop

PowerShell 下安装

1
2
3
4
5
iwr -useb get.scoop.sh | iex

scoop install sudo
sudo scoop install 7zip git openssh --global
scoop install curl grep sed less

neofetch

1
2
3
scoop install netfetch
netfetch
neofetch --ascii "$(fortune | cowsay -f dragon -W 30)" | lolcat -ats 60

cowsay

1
2
scoop install neo-cowsay
cowsay -f dragon hello

lolcat

rubyinstaller-devkit-3.1.2-1-x64.exe 下载安装 RubyInstaller

1
gem install lolcat

MSYS2

1
winget install msys2.msys2
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
"profiles": {
  "list":
  [
    // ...
    {
      "guid": "{17da3cac-b318-431e-8a3e-7fcdefe6d114}",
      "name": "MINGW64 / MSYS2",
      "commandline": "C:/msys64/msys2_shell.cmd -defterm -here -no-start -mingw64",
      "startingDirectory": "C:/msys64/home/%USERNAME%",
      "icon": "C:/msys64/mingw64.ico",
      "font": 
      {
        "face": "Lucida Console",
        "size": 9
      }
    }
  ]
}

fish

pacman 是 MSYS2 的一个包管理器

1
2
3
pacman -Syu
pacman -S fish
fish
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
"profiles": {
  "list":
  [
    // ...
    {
      "guid": "{17da3cac-b318-431e-8a3e-7fcdefe6d114}",
      "name": "MINGW64 / MSYS2",
      "commandline": "C:/msys64/msys2_shell.cmd -defterm -here -no-start -mingw64 -shell fish",
      "startingDirectory": "C:/msys64/home/%USERNAME%",
      "icon": "C:/msys64/mingw64.ico",
      "font": 
      {
        "face": "Lucida Console",
        "size": 9
      }
    }
  ]
}
1
pacman -S tree

编辑器使用 Git Bash

IDEA termial shell path C:\Program Files\Git\bin\bash.exe -i -l

VS Code 配置

1
2
3
4
5
6
7
{
    "editor.fontFamily":"CaskaydiaCove Nerd Font Mono, 'Consolas', Microsoft YaHei UI",
    "editor.fontSize": 17,
    "explorer.confirmDelete": false,
    "terminal.integrated.defaultProfile.windows": "Git Bash",
    "terminal.integrated.fontSize": 20
}

附录