tompreston
tompreston

Reputation: 690

How do I set tmux window name from within a Bash script?

In one of my tmux windows, I run a Weechat IRC client inside a Docker container, which I instantiate using a Bash script, which makes the tmux window name "bash". https://i.sstatic.net/Nn4nd.jpg

I would like the tmux window name to be "weechat", as if I had run a locally installed weechat - as is the case with man or nvim.

I understand there is a difference between "window names" and "pane titles", and that I can set the window name using (as detailed in the man page):

tmux set-option allow-rename on
tmux select-pane -T fooname
printf '\033kWINDOW_NAME\033\\'

But this changes my window name to 1:tpreston@hostname:~*. I'm running tmux 2.9a on Fedora 30.

These are my options

activity-action other
assume-paste-time 1
base-index 0
bell-action any
default-command ""
default-shell "/bin/bash"
default-size "80x24"
destroy-unattached off
detach-on-destroy on
display-panes-active-colour red
display-panes-colour blue
display-panes-time 1000
display-time 4000
history-limit 50000
key-table "root"
lock-after-time 0
lock-command "lock -np"
message-command-style fg=yellow,bg=black
message-style fg=black,bg=yellow
mouse on
prefix C-Space
prefix2 None
renumber-windows off
repeat-time 500
set-titles off
set-titles-string "#S:#I:#W - \"#T\" #{session_alerts}"
silence-action other
status on
status-bg green
status-fg black
status-format[0] "#[align=left range=left #{status-left-style}]#{T;=/#{status-left-length}:status-left}#[norange default]#[list=on align=#{status-justify}]#[list=left-marker]<#[list=right-marker]>#[list=on]#{W:#[range=window|#{window_index} #{window-status-style}#{?#{&&:#{window_last_flag},#{!=:#{window-status-last-style},default}}, #{window-status-last-style},}#{?#{&&:#{window_bell_flag},#{!=:#{window-status-bell-style},default}}, #{window-status-bell-style},#{?#{&&:#{||:#{window_activity_flag},#{window_silence_flag}},#{!=:#{window-status-activity-style},default}}, #{window-status-activity-style},}}]#{T:window-status-format}#[norange default]#{?window_end_flag,,#{window-status-separator}},#[range=window|#{window_index} list=focus #{?#{!=:#{window-status-current-style},default},#{window-status-current-style},#{window-status-style}}#{?#{&&:#{window_last_flag},#{!=:#{window-status-last-style},default}}, #{window-status-last-style},}#{?#{&&:#{window_bell_flag},#{!=:#{window-status-bell-style},default}}, #{window-status-bell-style},#{?#{&&:#{||:#{window_activity_flag},#{window_silence_flag}},#{!=:#{window-status-activity-style},default}}, #{window-status-activity-style},}}]#{T:window-status-current-format}#[norange list=on default]#{?window_end_flag,,#{window-status-separator}}}#[nolist align=right range=right #{status-right-style}]#{T;=/#{status-right-length}:status-right}#[norange default]"
status-format[1] "#[align=centre]#{P:#{?pane_active,#[reverse],}#{pane_index}[#{pane_width}x#{pane_height}]#[default] }"
status-interval 5
status-justify left
status-keys emacs
status-left "[#S] "
status-left-length 10
status-left-style default
status-position bottom
status-right "#(/home/tpreston/.tmux/plugins/tmux-battery/scripts/battery_status_bg.sh) b:#(/home/tpreston/.tmux/plugins/tmux-battery/scripts/battery_icon.sh)#(/home/tpreston/.tmux/plugins/tmux-battery/scripts/battery_percentage.sh) | %a %F %H:%M "
status-right-length 40
status-right-style default
status-style fg=black,bg=green
update-environment[0] "DISPLAY"
update-environment[1] "KRB5CCNAME"
update-environment[2] "SSH_ASKPASS"
update-environment[3] "SSH_AUTH_SOCK"
update-environment[4] "SSH_AGENT_PID"
update-environment[5] "SSH_CONNECTION"
update-environment[6] "WINDOWID"
update-environment[7] "XAUTHORITY"
visual-activity off
visual-bell off
visual-silence off
word-separators " -_@"

Upvotes: 2

Views: 3259

Answers (2)

Simba
Simba

Reputation: 27568

# rename window name of current window
tmux rename-window newname

# rename another window
tmux rename-window -t <target> new-name

The parameter <target> could be

  • window name
  • window index
  • window name or index with session prefix: <session>:<window>

Upvotes: 3

user11274868
user11274868

Reputation:

tmux select-pane -T fooname

This sets the pane title not the window name. Use "tmux rename-window" to change the window name.

tmux set-option allow-rename on

printf '\033kWINDOW_NAME\033\'

This does change the window name.

But this changes my window name to 1:tpreston@hostname:~*

This is because something else is renaming the window, probably your shell is doing it as part of the prompt.

If you want to have allow-rename on and use the \033k escape sequence yourself, you will need to track this down and disable it.

If your script is running on the same host as tmux, it might be better just to leave allow-rename off and run "tmux renamew weechat" from the script.

Upvotes: 1

Related Questions