DucDoc, thanks for your reply.
I am using
bash on Debian.
My PS1, which - like yours - DOES NOT set the terminal title, just the prompt:
(\W displays the current directory as a relative path, \w as an absolute path.)
Code:
echo $PS1
PS1=\u@\h \w \$
You can indeed set the title bar title by inserting the following sequence in
PS1:
Code:
PS1='\u@\h:\w\$ '
case $TERM in
xterm*)
TITLE='\u@\h - \w'
PS1="\[\e]0;$TITLE\w\a\]$PS1"
;;
[...]
The green part sets the terminal title, the blue part the prompt.
That, as I just realized, also works for me.
However, I am dynamically setting the prompt in order to get a different coloured $ sign depending on the return code of the last command:
The following code dynamically sets the prompt and the title using
PROMPT_COMMAND, where the function
set_bash_prompt sets the variable
$PROMPT:
Code:
PROMPT_COMMAND='set_bash_prompt;echo -ne "\e]0;${HOSTNAME} : ${PWD} (${USER})\a"'
PS1="$PROMPT"
This also works for me, giving me a dynamically coloured prompt and dynamic title. I just don't like the fully qualified path of
$PWD.
The following attempt to set the title via
PS1 does not work:
Code:
PROMPT_COMMAND='set_bash_prompt'
PS1="\[\e]0;$TITLE\w\a\]$PROMPT"
The contents of
PROMPT_COMMAND are executed as a regular Bash command just before Bash displays a prompt. This somehow conflicts with setting the title dynamically via
PS1.
Any work-arounds would be greatly appreciated.