Loading

msys2 环境配置记录

命令行添加镜像地址

首次安装后,配置软件源

#https://mirrors.tuna.tsinghua.edu.cn/help/msys2/

sed -i "1iServer = https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw/i686" /etc/pacman.d/mirrorlist.mingw32
sed -i "1iServer = https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw/x86_64" /etc/pacman.d/mirrorlist.mingw64
sed -i "1iServer = https://mirrors.tuna.tsinghua.edu.cn/msys2/msys/\$arch" /etc/pacman.d/mirrorlist.msys
sed -i "1iServer = https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw/ucrt64" /etc/pacman.d/mirrorlist.ucrt64
sed -i "1iServer = https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw/clang64" /etc/pacman.d/mirrorlist.clang64

注意:最新版本20200720已自带清华与中科大镜像配置,可手动将国内源提前

Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/
Server = http://mirrors.ustc.edu.cn/msys2/

更新

pacman -Syu #首次更新要求重启,重启后需重新配置软件源
pacman -Su

配置右键菜单

使用WScript是为了解决启动时窗体闪烁的问题。

创建文件msys2_here.vbs,我放在了 "D:\software"

set ws=WScript.CreateObject("WScript.shell")
ws.Run "C:\msys64\msys2_shell.cmd -mingw64 -here", 0

创建msys2 here.reg ,用于在注册表中创建菜单。将"D:\software"改为自己的路径,双击注册表文件导入即可

Windows Registry Editor Version 5.00

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

[HKEY_CLASSES_ROOT\Directory\Background\shell\msys2_shell\command]
@="WScript \"D:\\software\\msys2_here.vbs\""

参考:
https://zhuanlan.zhihu.com/p/33789023

配置桌面快捷方式

和上一节类似,主要为了解决窗口闪烁问题
新建文件D:\software\msys2.vbs

set ws=WScript.CreateObject("WScript.shell")
ws.Run "C:\msys64\msys2_shell.cmd -mingw64", 0

通过右键菜单-新建快捷方式,输入

C:\Windows\System32\wscript.exe "D:\\software\\msys2.vbs"

修改快捷方式图标为

%SystemDrive%\msys64\mingw64.ico

访问windows PATH环境变量

三种方法选择一个就可以:

  1. msys2_shell.cmd 中取消一行的注释:set MSYS2_PATH_TYPE=inherit
  2. 调用msys2_shell.cmd时使用-use-full-path参数
  3. 在windows系统的环境变量中添加 MSYS2_PATH_TYPE=inherit

参考:
https://segmentfault.com/q/1010000016064839/a-1020000016068252
https://sourceforge.net/p/msys2/discussion/general/thread/dbe17030/

配置home路径为windows用户目录

/etc/nsswitch.conf

db_home: windows

参考:
https://superuser.com/questions/809974/msys2-home-folder-show
https://github.com/valtron/llvm-stuff/wiki/Set-up-Windows-dev-environment-with-MSYS2
https://cygwin.com/cygwin-ug-net/ntsec.html#ntsec-mapping-nsswitch

配置clion所需的编译环境

pacman -S mingw-w64-x86_64-toolchain

# 输出结果为:

:: 在组 mingw-w64-x86_64-toolchain 中有 17 成员:
:: 软件仓库 mingw64
1) mingw-w64-x86_64-binutils 2) mingw-w64-x86_64-crt-git
3) mingw-w64-x86_64-gcc 4) mingw-w64-x86_64-gcc-ada
5) mingw-w64-x86_64-gcc-fortran 6) mingw-w64-x86_64-gcc-libgfortran
7) mingw-w64-x86_64-gcc-libs 8) mingw-w64-x86_64-gcc-objc
9) mingw-w64-x86_64-gdb 10) mingw-w64-x86_64-headers-git
11) mingw-w64-x86_64-libmangle-git 12) mingw-w64-x86_64-libwinpthread-git
13) mingw-w64-x86_64-make 14) mingw-w64-x86_64-pkg-config
15) mingw-w64-x86_64-tools-git 16) mingw-w64-x86_64-winpthreads-git
17) mingw-w64-x86_64-winstorecompat-git

选择安装gcc ,gdb ,make的安装序号即可
参考:
https://blog.csdn.net/weixin_41624493/article/details/80639775
https://blog.csdn.net/imzhujun/article/details/80707635

显示git branch

不建议使用msys2代替git for windows,实在需要可考虑安装git for windows sdk代替msys2
在.bashrc或.bash_profile中添加以下内容

function parse_git_branch () {
  git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
  
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
NO_COLOR="\[\033[0m\]"
  
PS1="$GREEN\u@\h$NO_COLOR:\w$YELLOW\$(parse_git_branch)$NO_COLOR\$ "

git for windows ps1:

\[\033]0;$TITLEPREFIX:$PWD\007\]\n\[\033[32m\]\u@\h \[\033[35m\]$MSYSTEM \[\033[33m\]\w\[\033[36m\]`__git_ps1`\[\033[0m\]\n$

参考:
https://gist.github.com/githubteacher/e75edf29d76571f8cc6c

转载请注明出处: cnblogs.com/wswind
posted @ 2019-04-03 17:07  wswind  阅读(7311)  评论(0编辑  收藏  举报