I worked around my own solution from various posts around. This creates a title containing user, hostname, pwd, tty and currently executed command (for bash).
This looks like this (no command being executed):
.:[user@hostname:/home/user][pts/10]:.
And like this (executing a command):
.:[user@hostname:/home/user][pts/10] {tail -F /var/log/syslog}:.
Somewhere in the .bashrc, i extended PS1:
# set the terminals title. This is the "post-command" part,
# need to use a trap for pre-command (to add the command line to the title)
PS1+="\[\033]2;.:[\u@\h:\$PWD] [$(tty | cut -b 6-)]:.\007\]"
Adds the current command, using history 1 and trap:
# set a fancy title (this is pre-command, in PS1 is after-command (to reset command)
trap 'echo -ne "\033]2;.:[${USER}@${HOSTNAME}:${PWD}] [$(tty | cut -b 6-)] {$(history 1 | sed "s/^[ ]*[0-9]*[ ]*//g")}:.\007"' DEBUG
Feel free to adopt to your needs.
.bashrc
after each command in my shell I get this output0;%s@%s:%s" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}
. I assume that I can suppress this output by assigning the trap command toPS1
? However,PS1=trap 'echo -ne "\033]0;$BASH_COMMAND\007"' DEBUG
does not work. It leads to the errorbash: echo -ne "\033]0;$BASH_COMMAND\007": command not found
. – orschiro Dec 07 '13 at 08:17trap
command as a separate command, not to assign it to PS1. – Charles Duffy Jan 23 '18 at 17:29