背景
git bash
默认的标题是 MINGW64:{path}
在 windows 的任务栏预览界面,看到的是这样

一旦开的多了,根本分不清谁是谁,要一个一个找过去
那能不能解决呢?
1. 去掉 MINGW64 前缀
这个答案在 here
就是修改你的 git-prompt.sh
这个脚本路径一般在 c:\Program Files\Git\etc\profile.d\git-prompt.sh
(没有的话,用everything
搜一下)
- 备份你的默认脚本
- 修改为以下内容(全文覆盖就行)
if test -z "$GITTITLEPREFIX" # if not empty
then
GITTITLEPREFIX="Git-Bash => " # prefix that will have current pwd appended after it
fi
if test -f ~/.config/git/git-prompt.sh
then
. ~/.config/git/git-prompt.sh
else
if test -n "$GITTITLE"
then ##### Set window title directly to GITTITLE if not empty
PS1='\[\033]0;$GITTITLE\007\]'
else ##### Set window title to GITTITLE PREFIX plus the PWD
PS1='\[\033]0;$GITTITLEPREFIX${PWD//]^[:ascii:]]/?}\007\]'
fi
fi
###### Leave the rest of the file the same
PS1="$PS1"'\n'
PS1="$PS1"'\[\033[32m\]'
###### Etc.
然后右键--git bash,就能看到效果了
不过仅仅只是去掉前缀而已,该看不见还是看不见(如果觉得效果不满意,把刚刚备份的内容还原回去就行)
2. 自定义标题
还是刚刚那个帖子,有大佬分享了一种思路,可行,
大佬原文在 here
步骤如下:
- 复制你的
git-prompt.sh
到C盘根目录,改名为changename.sh
这一步是为了生成一个linux
格式的文件,换行符是\n
, 如果创建的话,默认是\r\n
;如果你知道怎么调整格式,直接在C盘下面创建空文件也可以 - 把内容覆盖为如下内容:
if test -f /etc/profile.d/git-sdk.sh
then
TITLEPREFIX=SDK-${MSYSTEM#MINGW}
else
TITLEPREFIX=$MSYSTEM
fi
name=$1
PS1='\[\033]0;$name\007\]' # set window title
PS1="$PS1"'\n' # new line
PS1="$PS1"'\[\033[32m\]' # change to green
PS1="$PS1"'\u@\h ' # user@host<space>
#PS1="$PS1"'\[\033[35m\]' # change to purple
#PS1="$PS1"'$MSYSTEM ' # show MSYSTEM
PS1="$PS1"'\[\033[33m\]' # change to brownish yellow
PS1="$PS1"'\w' # current working directory
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[36m\]' # change color to cyan
PS1="$PS1"'`__git_ps1`' # bash function
fi
fi
PS1="$PS1"'\[\033[0m\]' # change color
PS1="$PS1"'\n' # new line
PS1="$PS1"'$ ' # prompt: always $
MSYS2_PS1="$PS1" # for detection by MSYS2 SDK's bash.basrc
- 在需要修改标题的
Git Bash
窗口里执行. /c/changename.sh v2
(v2就是你想要的名字)
以下是效果


网友评论