title: How do I set tmux window name from within a Bash script?
body: <p>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". <a href="https://imgur.com/a/Dc20YEB" rel="nofollow noreferrer">https://imgur.com/a/Dc20YEB</a></p>
  
  <p>I would like the tmux window name to be "weechat", as if I had run a locally installed weechat - as is the case with <code>man</code> or <code>nvim</code>.</p>
  
  <p>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):</p>
  
  <pre><code>tmux set-option allow-rename on
  tmux select-pane -T fooname
  printf '\033kWINDOW_NAME\033\\'
  </code></pre>
  
  <p>But this changes my window name to <code>1:tpreston@hostname:~*</code>. I'm running tmux 2.9a on Fedora 30.</p>
  
  <p>These are my options</p>
  
  <pre><code>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]&lt;#[list=right-marker]&gt;#[list=on]#{W:#[range=window|#{window_index} #{window-status-style}#{?#{&amp;&amp;:#{window_last_flag},#{!=:#{window-status-last-style},default}}, #{window-status-last-style},}#{?#{&amp;&amp;:#{window_bell_flag},#{!=:#{window-status-bell-style},default}}, #{window-status-bell-style},#{?#{&amp;&amp;:#{||:#{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}}#{?#{&amp;&amp;:#{window_last_flag},#{!=:#{window-status-last-style},default}}, #{window-status-last-style},}#{?#{&amp;&amp;:#{window_bell_flag},#{!=:#{window-status-bell-style},default}}, #{window-status-bell-style},#{?#{&amp;&amp;:#{||:#{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 " -_@"
  </code></pre>