Reputation: 507
I work in Windows 10 and usually I have up to 5 CMD windows open. I work this way because I need to run the same application with different data and keep monitoring if any exception is thrown.
I set a number as the window's title (using the title
command) instead of the default text, in order to easily identify which window I'm working in and be able to identify and change between them using Alt+Tab
(an example of how I work with my CMD windows)
Recently I started to use Git and I really like the Git Bash terminal for Windows. I would like to work with Git Bash terminal the same way I work with CMD windows, but I can't find any way to change the window title. I searched a bit and found these instructions and some others (that I can't paste because I'm not allowed to post more than two links yet), but it seems to work only by setting a different default title. I'd like to change the window title to any custom text I choose, at any moment.
Is this possible? Is there a command like title
available for Git Bash?
Upvotes: 32
Views: 20267
Reputation: 116
Here is a simple way to change the title text to anything you want. create a title.sh script somewhere on your system like in C:\bin that has the following content:
#!/bin/sh
export TITLEPREFIX="$*"
Add the following to your .bashrc file in your home directory.
alias title='. /c/bin/title.sh'
Now open a git bash window. You can now type:
title my title
and your title will start with the title you provided to the title alias.
Upvotes: 1
Reputation: 19
This thread is old but if anyone is still looking for a solution,
Terminal> Settings> Tab title>
Change it to anything you would like then scroll down.
Advanced> Suppress title changes> Turn on> Save
I hope this helps you!
Upvotes: 1
Reputation: 31
I know this is old, but if it helps someone, you can set the title prefix simply by changing the TITLEPREFIX env variable:
TITLEPREFIX=YourTitlePrefix
Upvotes: 3
Reputation: 2260
You could use
export MYTITLE=abcd; export PS1=$(echo $PS1 | sed -r "s/(0;).*?(\\\\007)/\1$MYTITLE\2/")
It find regular expression for title and replace it with $MYTITLE
.
I could be wrong but I assume title is something between 0;
and \007
in $PS1
. It work for me.
Or you could add next function to your .bashrc
(or .bash_profile
)
ttt() {
# change title in gitbash
export PS1=$(echo $PS1 | sed -r "s/(0;).*?(\\\\007)/\1$1\2/")
}
and then anytime use ttt "new title"
Upvotes: 3
Reputation: 68
In JSON setting write for Git Console:
"name": "Git Bash",
"tabTitle": "Git Bash",
"suppressApplicationTitle": true
Upvotes: 4
Reputation: 11659
You were on the right track with this link
If you modify the git-prompt.sh
script a bit (for me, this is located in c:\Program Files (x86)\Git\etc\profile.d\git-prompt.sh
), you can make the title anything you want.
Note: You will need to run VS Code, Notepad++ or similar as administrator to write back to this directory.
First, save a backup of git-prompt.sh
(like git-prompt.backup.sh
), then modify the start of git-prompt.sh
as follows:
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.
This will first check if GITTITLEPREFIX is empty, and if not, it will set it to "Git-Bash => " similar to in the linked article. This will have the current path appended after it, so if you want "1 : $PWD", then set GITTITLEPREFIX to "1 : " like this:
GITTITLEPREFIX="1 : "
Otherwise, you can set GITTITLE to any non-empty value, and then the entire title will be set exactly to the contents of GITTITLE (no PWD appended), so if you just want "1", use this:
GITTITLE="1"
Then run the script. With my path, I did it like this:
. "/c/Program Files (x86)/Git/etc/profile.d/git-prompt.sh"
and the title should change. Of course, you can alias this or make a separate script from it in a location that is in the path so running it is much simpler, and the title could just be an argument. I'll leave that as an exercise for the reader...
Upvotes: 14
Reputation: 211
This thread is a few months old. But I think an alternative will be helpful
You can add following line to .bashrc file in your user profile folder
export TITLEPREFIX="Git Bash"
where you want Git bash to be your title prefix. This is user specific change. So if a machine is used by multiple users with their own logins, everyone can customize their own title.
Upvotes: 19
Reputation: 507
I solved my question making very little modifications to the script.
The first one, to pass the name I want for the window, I added the variable name=$1
and set it in the title variable:
name=$1
PS1='\[\033]0;$name\007\]' # set window title
The second one, as recommended here, I commented the next lines:
#PS1="$PS1"'\[\033[35m\]' # change to purple
#PS1="$PS1"'$MSYSTEM ' # show MSYSTEM
The final code is below:
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
Temporally I made a copy of the script and pasted it on C:, to execute it easily every time I need to change the title, according to my path, as as follows:
$ . /c/changename.sh
I'm still learning about scripting so I could be able to set an alias. As @LightCC said, "I'll leave that as an exercise for the reader..."
Upvotes: 2