前言
git bash 使用了mingw,这给扩展带来了极大可能性,但是由于精简,gitbash的mingw-get
(mingw的包管理工具)是被删除了的,但是安装扩展要和git bash分开,进行额外安装,因为他们的动态库有一些不一致,如果强行覆盖动态库将导致部分软件无法启动
step1 下载mingw-get
官网http://www.mingw.org/
mingw-get下载地址https://mirrors.tuna.tsinghua.edu.cn/osdn/mingw/68260/mingw-get-setup.exe
2023-02-21 补充 事物总在发生变化,随着时间流逝,有些东西总是不一样了 下载地址: https://sourceforge.net/projects/mingw-w64/
step2 安装
随便安装到一个地方,选项自选,看个人喜好
step3 git bash关联
在gitbash里找到你安装的位置
/c/MinGW/bin/mingw-get.exe --version #检查位置是否正确
cp ~/.bash_profile ~/.bash_profile.bak.`date '+%Y-%m-%d.%H:%M:%S'` #备份
echo 'export PATH=$PATH:/c/MinGW/bin' >> ~/.bash_profile #注意替换正确的bin路径和使用单引号,否则会自动翻译变量
source ~/.bash_profile #刷新当前bash
git bash下测试
更新软件列表
mingw-get update
查看可安装的包
mingw-get list|grep Package
安装make(linux下makefile利器)
mingw-get list|grep Package|grep make #查找名字包含make的包
mingw-get install mingw32-make #安装make
mingw32-make
1)如果mingw32-make中文乱码
二进制文件返回的中文是gbk编码,解决方式有两种
- 设置git bash编码为GBK
在gitbash页面右键打开Options
选择编码为gbk,但这个方法缺点是ssh连接linux时因为linux编码是utf-8而乱码,还得改成utf-8,还是以utf-8为标准不推荐该方案 - 使用命令行代理转换输出流
例子:commandproxy.sh
#!/bin/bash
bashname=$(basename $0)
$@ 1> /tmp/$bashname.out 2>/tmp/$bashname.err
state=$?
iconv -f GB2312 -t UTF-8 /tmp/$bashname.out
if test -s /tmp/$bashname.err; then
iconv -f GB2312 -t UTF-8 /tmp/$bashname.err 1>&2
exit $state
fi
使用方法 sh commandproxy.sh mingw32-make
将输出utf-8编码的中文
一劳永逸的话在bin目录下编写
make
#!/bin/bash
bashname=$(basename $0)
mingw32-make $@ 1> /tmp/$bashname.out 2>/tmp/$bashname.err
state=$?
iconv -f GB2312 -t UTF-8 /tmp/$bashname.out
if test -s /tmp/$bashname.err; then
iconv -f GB2312 -t UTF-8 /tmp/$bashname.err 1>&2
exit $state
fi
然后就可以使用make
了