git bash 优化
下文中以我的用户目录(C:\Users\Administrator)为例。
配置 alias
用户目录下创建 .bash_profile
文件
提示:打开“此电脑”,在文件夹地址栏中输入 %userprofile%(Mac系统请点击前往 > 个人),即可进入个人用户目录。
touch .bash_profile
# Bash config
alias bashp_rofile='code ~/.bash_profile'
alias bashcolor='code ~/.minttyrc'
alias bashconfig='code /etc/profile.d/git-prompt.sh'
alias gitconfig='code ~/.gitconfig'
# File system
alias .='cd ~'
alias ..='cd ..'
alias ...='cd ../..'
alias e='exit'
alias cls='clear'
alias md='mkdir'
alias desktop='cd E:\Desktop'
alias codedir='cd E:\代码'
# Git
alias gs='git status'
alias ga='git add .'
alias gc='git commit -m'
alias gp='git push'
alias gitauto='git add . && git commit -m "auto deploy" && git push'
# System
alias sysoff='shutdown -s -t 0'
alias sysre='shutdown -r -t 0'
alias host='code /c/Windows/System32/drivers/etc/hosts'
# NPM
alias start='npm start'
alias serve='npm run serve'
alias build='npm run build'
alias test='npm run test'
alias lint='npm run lint'
alias preview='npm run preview'
配置外观
.minttyrc
用户目录下创建 .minttyrc
touch .minttyrc
Language=zh_CN
Transparency=low
Locale=C
Charset=UTF-8
OpaqueWhenFocused=no
Scrollbar=none
BellTaskbar=no
Term=xterm
Columns=88
Rows=26
Font=Consolas
FontHeight=10
FontWeight=400
FontIsBold=no
FontSmoothing=default
ForegroundColour=255,255,255
BackgroundColour=43,43,43
CursorColour=0,255,64
Black=0,0,0
BoldBlack=0,0,0
Red=130,68,6
BoldRed=246,155,64
Green=6,130,68
BoldGreen=64,246,155
Yellow=68,130,6
BoldYellow=155,246,64
Blue=68,6,130
BoldBlue=155,64,246
Magenta=130,6,68
BoldMagenta=246,64,155
Cyan=6,68,130
BoldCyan=64,155,246
White=255,255,255
BoldWhite=255,255,255
配置 git-prompt.sh
通过命令打开 git-prompt.sh。
code /etc/profile.d/git-prompt.sh
或者通过路径 C:\Program Files\Git\etc\profile.d\git-prompt.sh
打开。
if test -f /etc/profile.d/git-sdk.sh
then
TITLEPREFIX=SDK-${MSYSTEM#MINGW}
else
TITLEPREFIX=$MSYSTEM
fi
if test -f ~/.config/git/git-prompt.sh
then
. ~/.config/git/git-prompt.sh
else
PS1='\[\033]0;Bash\007\]' # 窗口标题
PS1="$PS1"'\n' # 换行
PS1="$PS1"'\[\033[32;1m\]' # 高亮绿色
PS1="$PS1"'>> ' # unicode 字符
PS1="$PS1"'\[\033[33;1m\]' # 高亮黄色
PS1="$PS1"'\W' # 当前目录
if test -z "$WINELOADERNOEXEC"
then
GIT_EXEC_PATH="$(git --exec-path 2>/dev/null)"
COMPLETION_PATH="${GIT_EXEC_PATH%/libexec/git-core}"
COMPLETION_PATH="${COMPLETION_PATH%/lib/git-core}"
COMPLETION_PATH="$COMPLETION_PATH/share/git/completion"
if test -f "$COMPLETION_PATH/git-prompt.sh"
then
. "$COMPLETION_PATH/git-completion.bash"
. "$COMPLETION_PATH/git-prompt.sh"
PS1="$PS1"'\[\033[31m\]' # 红色
PS1="$PS1"'`__git_ps1`' # git 插件
fi
fi
PS1="$PS1"'\[\033[36m\] ' # 青色
fi
MSYS2_PS1="$PS1"
参考资料
[1] 为 win10 打造 Linux 终端(非 wsl)