I recently added these lines to my ~/.bashrc file to show the current branch if i’m in a git working folder, and it works nicely for that. However, what i’ve lost is that the current folder name used to be shown in the tab for the terminal i have open, and now it isn’t: it always just says ‘Terminal’. Can i get that back and still keep the git stuff? Here’s the lines in question – it’s the second one that’s the issue, as commenting out just the second line fixes the problem.
source /etc/bash_completion.d/git
PS1='\h:\w$(__git_ps1 "\[\e[32m\][%s]\[\e[0m\]")$ '
I’ve been looking at explanations of the options for PS1 but can’t see anything about the terminal window’s title in there. Can anyone advise? thanks, max
EDIT
I actually manipulate PS1 already in order to have a terminal with the format
<rvm version and gemset> <computer name> <current folder> <git branch>
, with each part in a different color, but i’ve never actually seen the docs before, so thanks for the link to that. My current PS1 setting is
\[\033[0;31m\]$(__my_rvm_ruby_version)\[\033[0;33m\]\h\[\033[0;37m\]:\[\033[1;33m\]\W\[\033[1;32m\]$(__git_branch)\[\033[1;32m\]$(__git_dirty) \[\033[0;37m\]$
Presumably i can do something like
export "<something> $PS1"
to set my terminal tab name without losing my existing settings. I’ve been poking around with this though and not managed to do it.
EDIT – figured this out with the help of some of the answers below – thanks all! I wrapped it up in a shell script
#!/usr/bin/env bash
#renames the current terminal tab via the PS1 env var
source ~/.bashrc
export PS1="$PS1""\[\e]0;$1 \a\]"
it’s called “renametab” so i can now call it with eg
source renametab mytabname
“source” is needed to export the changes into the current shell: if i just do renametab mytabname the export just goes into a subshell which is killed when the script finishes.
Thanks again all, for the help!
That’s what I have as default on my Ubuntu concerning the terminal’s title:
Prepend your PS1 with this one and it should be fine