To start tmux
on every shell login, the following was added to the ~/.bashrc
(on the server):
if [ $TERM != "screen-256color" ] && [ $TERM != "screen" ]; then
tmux attach || tmux new; exit
fi
I also want to change the window title to something like user@server
(instead of user@localhost
) when ssh into a host. Here's my ~/.tmux.conf
:
set -g prefix C-a
unbind C-b
bind C-a send-prefix
set -g set-titles on
set -g set-titles-string "#T"
bind-key o split-window -v
bind-key e split-window -h
bind-key w kill-pane
set -g terminal-overrides 'xterm*:smcup@:rmcup@'
As you can see, set-titles
was set to on
, but it doesn't work as expected.
More informations:
Outside of tmux:
$ echo $TERM
xterm
Inside of tmux:
$ echo $TERM
screen
show -g
: https://clbin.com/h7oDh
tmux info
: http://sprunge.us/XHCB
And here're the logs when running tmux -vvvvv
for a bit:
- tmux-client-8441.log: https://clbin.com/eFwFF
- tmux-out-8443.log: https://clbin.com/MSKZv
- tmux-server-8443.log: https://clbin.com/JXwRN
If I comment out the lines in ~/.bashrc
, from my laptop, ssh to the server, the title bar shows correctly (quanta@server
), then start tmux
from there also works as expected.
But if I want to start tmux
immediately after login, the title bar remains to be quanta@Ubuntu
after ssh.
UPDATE Fri May 10 07:51:23 ICT 2013
I have deleted the exit
command in order not to close the shell session when the last tmux
window is closed:
if [ $TERM != "screen-256color" ] && [ $TERM != "screen" ]; then
tmux attach || tmux new
fi
The strange thing is:
- ssh to server -> the title bar:
quanta@Ubuntu
- detach from
tmux
-> the title bar switch toquanta@server
- attach to
tmux
again -> the title bar still shows correctly
quanta@server
I'm not sure if it's related to the PROMPT_COMMAND
environment variable or not:
Outside of tmux
:
$ echo $PROMPT_COMMAND
echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}"; echo -ne "\007"
Inside of tmux
:
$ echo $PROMPT_COMMAND
echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}"; echo -ne "\033\\"
Best Answer
Problem solved!
To enable native xterm mouse scrolling in
tmux
, a lot of wiki, Q & A site, blog post suggest adding a line like:to
~/.tmux.conf
. And it is the culprit.To allow xterm titles in terminal window, you also need to add the
XT
flag, something like this:Source: http://opennomad.com/content/goodbye-screen-hello-tmux