我的Windows终端

Terminal - 工欲善其事,必先利其器

现在推荐git-bash 简单才是王道,不用任何配置

必备工具

  • mycli
  • iredis

mycli的坑 https://blog.csdn.net/banerye/article/details/115857927

Alias
1
2
3
4
5
6
7
cat ~/.bash_profile
# generated by Git for Windows
test -f ~/.profile && . ~/.profile
test -f ~/.bashrc && . ~/.bashrc
## Add by boer.
alias mysql='winpty mycli'
alias redis-cli='winpty iredis'

VSCode配置

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
{
"files.eol": "\n",
"terminal.integrated.profiles.windows": {
"Boer Bash": {
"path": "D:/Program Files/PortableGit/bin/bash.exe",
"args": [
"-l",
"-i",
]
}
},
"terminal.integrated.defaultProfile.windows": "Boer Bash",
"http.proxy": "http://127.0.0.1:10809",
"http.proxyStrictSSL": false,
"workbench.startupEditor": "none",
"workbench.iconTheme": "vscode-icons",
"redhat.telemetry.enabled": true,
"workbench.editor.untitled.hint": "hidden",
"vs-kubernetes": {
"vscode-kubernetes.kubectl-path.windows": "C:\\Users\\boer\\.vs-kubernetes\\tools\\kubectl\\kubectl.exe",
"vscode-kubernetes.minikube-path.windows": "C:\\Users\\boer\\.vs-kubernetes\\tools\\minikube\\windows-amd64\\minikube.exe",
"vscode-kubernetes.helm-path.windows": "C:\\Users\\boer\\.vs-kubernetes\\tools\\helm\\windows-amd64\\helm.exe"
},
"python.formatting.provider": "yapf",
"python.formatting.yapfPath": "D:/Program Files/venv/Scripts/yapf.exe",
"editor.fontSize": 15,
"files.exclude": {
".venv": true
}
}

1、安装Windows Terminal

https://aka.ms/terminal

2、安装配置MSYS2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
MSYS2是什么
https://www.msys2.org/wiki/How-does-MSYS2-differ-from-Cygwin/
# pacman 源配置
https://mirrors.tuna.tsinghua.edu.cn/help/msys2/
nano /etc/pacman.d/mirrorlist.mingw64
ctrl + x -> y/n
# 刷新软件包数据
pacman -Sy
# 安装必备软件包
pacman -S vim
pacman -S gcc
# 变更Home目录
vim /etc/nsswitch.conf
# https://stackoverflow.com/questions/33942924/how-to-change-home-directory-and-start-directory-on-msys2
db_home: windows

3、安装oh-my-zsh

1
2
3
# https://ohmyz.sh/#install
# 注意科学上网
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

4、Windows Terminal集成MSYS2

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
{
"defaultProfile": "{2c4de342-38b7-51cf-b940-2309a0970924}",
"copyOnSelect": true,
"profiles":
{
"defaults":
{
// Put settings here that you want to apply to all profiles.
},
"list":
[
{
"guid": "{2c4de342-38b7-51cf-b940-2309a0970924}",
"name": "MSYS2",
"padding": "0, 0, 0, 0",
"snapOnInput": true,
"closeOnExit": "graceful",
"cursorShape": "filledBox",
"commandline": "D:/msys64/msys2_shell.cmd -full-path -defterm -here -no-start -mingw64 -shell zsh",
"icon": "D:/msys64/msys2.ico",
"hidden": false
}
]
}
}

参数解析
D:/msys64/msys2_shell.cmd -full-path -defterm -here -no-start -mingw64 -shell zsh

  • -full-path: Windows环境变量
  • -shell: 指定启动shell

    具体可以参考msys2安装目录下msys2_shell.cmd、msys2.ini两个文件

5、VSCode集成

1
2
3
4
5
6
7
8
9
10
11
12
13
{
"terminal.integrated.shell.windows": "D:/msys64/usr/bin/zsh.exe",
"terminal.integrated.env.windows": {
"MSYSTEM": "MINGW64",
"CHERE_INVOKING": "1",
"MSYS2_PATH_TYPE": "inherit"
},
"terminal.integrated.shellArgs.windows": [
"-l",
"-i"
],
}
# python虚拟环境在zsh环境下不能自动激活 @TODO

6、附录|参考

https://stackoverflow.com/questions/45404631/msys2-not-finding-windows-programs-despite-msys2-path-type-inherit


我的Windows终端
https://www.boer.xyz/2016/09/24/windows-terminal-msys2/
作者
boer
发布于
2016年9月24日
许可协议