记Windows与MSYS2的磨合

之前Git Bash自带的右键管理菜单怎么没有了?

不用慌张,只需在注册表里加上就可以,其实就是对着Git Bash的照抄。

这里以安装目录d:\msys64,默认shell为zsh为例:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\msys2_shell]
@="MSYS2 Here"
"Icon"="d:\\msys64\\msys2.ico"

[HKEY_CLASSES_ROOT\Directory\Background\shell\msys2_shell\command]
@="C:\\Windows\\System32\\wscript.exe d:\\msys64\\msys2_open.vbs -shell zsh -use-full-path -here"

[HKEY_CLASSES_ROOT\Directory\shell\msys2_shell]
@="MSYS2 Here"
"Icon"="d:\\msys64\\msys2.ico"

[HKEY_CLASSES_ROOT\Directory\shell\msys2_shell\command]
@="C:\\Windows\\System32\\wscript.exe d:\\msys64\\msys2_open.vbs -shell zsh -use-full-path -where \"%1\""

[HKEY_CLASSES_ROOT\sh_auto_file]
@="Shell Script"

[HKEY_CLASSES_ROOT\.sh]
@="sh_auto_file"

[HKEY_CLASSES_ROOT\sh_auto_file\DefaultIcon]
@="d:\\msys64\\mingw32.exe"

[HKEY_CLASSES_ROOT\sh_auto_file\shell]

[HKEY_CLASSES_ROOT\sh_auto_file\shell\open]

[HKEY_CLASSES_ROOT\sh_auto_file\shell\open\command]
@="C:\\Windows\\System32\\wscript.exe d:\\msys64\\msys2_open.vbs \"%L\" %*"

[HKEY_CLASSES_ROOT\sh_auto_file\ShellEx]

[HKEY_CLASSES_ROOT\sh_auto_file\ShellEx\DropHandler]
@="{60254CA5-953B-11CF-8C96-00AA00B8708C}"

下面是d:\\msys64\\msys2_open.vbs,用 vbs 可以去掉一闪而过的黑色窗口

Dim args
For Each arg In Wscript.Arguments
    args = args & " " & arg
Next
WScript.CreateObject("WScript.Shell").Run "d:\\msys64\\msys2_shell.cmd " & args,0

关于DropHandler我也不是很懂,反正抄来就能用,也不管那么多。

这样就顺带着把.sh文件的双击打开解决了。

GVim检测不到Git了?!

简单粗暴一点的话,就在Windows的环境变量PATH中添加D:\msys64\usr\bin,这样几乎所有命令都可以舒服地使用,除了少数如time和cmd自带命令冲突无法使用。

注意: 如果单单设置gitgutter_git_executable之类的变量仍然会报错,应为它还需要其他一些dll才能运行

VS Code 对 Git 怎么还是不行?

参考https://github.com/microsoft/vscode/issues/4651

就是重新把 Git 包装一下

GVim和MSYS2的Vim如何共享配置?

本来Gvim和Git Bash的Vim所在的家目录是同一个,现在分居两处。只需让GVim从Windows家目录引到MSYS2的即可。

于是在Windows家目录下的_vimrc中写(以~/.vim/vimrc为例):

set guifont=Powerline\ Consolas:h15
set go= 
" 以上两行不重要,可以放入MSYS2中的vimrc里
" 共享历史记录之类的文件
let $HOME="D:\\msys64\\home\\AC"
set pp+=D:\msys64\home\AC\.vim
source D:\msys64\home\AC\.vim\vimrc
set rtp+=D:\msys64\home\AC\.vim

如何快乐地建一个用户bin目录?

  1. 新建这个目录并放入Windows和MSYS2的环境变量中
  2. 修改Windows环境变量的PATHEXT值,添加;.PY;.SH等值
  3. 修改之前的注册表文件,使用sh打开.sh文件(也就是不跳出MSYS2的窗口)
    [HKEY_CLASSES_ROOT\sh_auto_file\shell\open\command]
    @="D:\\msys64\\usr\\bin\\sh.exe \"%L\" %*"
    
  4. 这样就可以在Windows的cmd中输入hello来运行该目录下的hello.sh了,但是MSYS2中需要输入hello.sh
  5. 如果有强迫症的话,就加个链接吧

你可能感兴趣的:(MSYS2,GVim,注册表,环境配置)