Renaming a window in tmux - tmux

I'm using bind-key + , to rename my windows, but as soon as I type a command the name reverts back to the current working directory.
Is it possible to make the window name permanent?

The automatic rename function is turned on. Add the following to your .tmux.conf file (and/or run from the command line to have it take effect immediately):
set-window-option -g automatic-rename off

Per this superuser answer, I made the following change to ~/.tmux.conf:
# NO, window name keeps changing
# set -g default-terminal "screen-256color"
# YES, window name sticks
set -g default-terminal "xterm-256color"

Related

How to interpolate tmux variable in .tmux.conf?

How to interpolate a variable that was created inside .tmux.conf to be used for a longer command?
I have this in .tmux.conf:
# show window name if set by user
WINDOW_NAME='#{?#{==:#{window_name},#{pane_current_command}},#{pane_current_command},[#{window_name}]:#{pane_current_command}}'
set -g window-status-format $WINDOW_NAME
set -g window-status-current-format $WINDOW_NAME
Now this works fine, as in it shows the window status plus the current window name, but I would like to interpolate this variable something like this:
set -g window-status-format '$WINDOW_NAME > #{=21:pane_title}'
however it does not work, and instead of interpreting the variable it just shows $WINDOW_NAME > user#ip-10...
Assuming the current command was ssh the expected result would be ssh > user#ip-10...

tmux status-line: italicize zoomed window name?

I've customized my tmux statusline, and I'd like to add a visual indicator for when the current window is zoomed (resize-pane -Z).
I've seen several examples of how to apply a different foreground color,
setw -g window-status-current-format " #{?window_zoomed_flag,#[fg=red],#[fg=black]}#W#[fg=default]"
Since I have italics working in tmux, I want to apply them in this case. I tried:
setw -g window-status-current-format " #{?window_zoomed_flag,#[fg=red,italics],#[fg=black]}#W#[fg=default]"
but this doesn't work. When zoomed it just shows empty spaces, and when unzoomed it shows italics],bash ("bash" being the window_name).
It seems to be treating the , in #[fg=red,italics] as one of the separators for the overall conditional form,
#{?test,alternative1,alternative2}
It does correctly handle a comma embedded in alternative2, e.g.
setw -g window-status-current-format " #{?window_zoomed_flag,#[fg=red],#[fg=black,italics]}#W#[fg=default]"
so if I wanted to italicize the unzoomed window name, I'd be in luck, but since I don't have a way to turn the conditional around, I am SOL.
Does anyone know a way to get this working, or is this an issue I should bring to the tmux project?
I got it working and now I'm not sure I actually like it, but it's good to know that it can be done. It's not entirely clear from the documentation, but I noticed in this answer this answer that you can specify the text attribute in a separate #[] group instead of using a comma-separated list, so this works:
setw -g window-status-current-format " #{?window_zoomed_flag,#[fg=red]#[italics],#[fg=black]}#W#[fg=default]"
probably a bit outdated answer yet helpful for anyone out there that might need help!
I have managed to do that with the following code :)
I will post the whole status bar in case anyone finds it any helpfull
set -g status-left '#[fg=black,bg=green] #S#{prefix_highlight}#[fg=green,bg=black,nobold,nounderscore,noitalics]#[fg=green,bg=green]#{?mouse,#[fg=black] MOUSE#[bg=green]#[fg=green],#[bg=red]#[fg=green]#[fg=white]#[bg=red]MOUSE#[bg=green]#[fg=red]}#{?pane_synchronized,#[fg=black] SYNC#[bg=green]#[fg=green],#[bg=red]#[fg=green]#[fg=white]#[bg=red]SYNC#[bg=green]#[fg=red]}#{?window_zoomed_flag,#[fg=black] #[bg=green]#[fg=green],#[bg=red]#[fg=green]#[fg=white]#[bg=red]#[bg=green]#[fg=red]}#[fg=green,bg=black] #W #[fg=green,bg=black,nobold,nounderscore,noitalics]#[fg=green,bg=black] #(whoami) CPU: #{cpu_percentage}Online:#{online_status}#[fg=green,bg=black,nobold,nounderscore,noitalics]'
set -g status-right '#[fg=green,bg=black,nobold,nounderscore,noitalics]#[fg=green,bg=black]#[fg=green,bg=black,nobold,nounderscore,noitalics]#[fg=white,bg=black]Bat: #{battery_percentage}#[fg=green,bg=black,nobold,nounderscore,noitalics]#[fg=black,bg=green]#(rainbarf --battery --remaining )'
setw -g window-status-format '#[fg=green,bg=black,nobold,nounderscore,noitalics]#[default] #I  #W #[fg=green,bg=black,nobold,nounderscore,noitalics]'
setw -g window-status-current-format '#[fg=green,bg=black,nobold,nounderscore,noitalics]#[fg=green,bg=black] #I  #W  #F #[fg=green,bg=black,nobold,nounderscore,noitalics]'

binding the shift key in .tmux.conf doesn't work

This is my .tmux.conf file, placed in the home directory.
unbind C-b
set -g prefix S-a
bind S-a send-prefix
bind r source-file ~/.tmux.conf
I am properly loading it with tmux source-file ~/.tmux.conf. However, doing shift+a to initiate the prefix doesn't work.
However if I replace S-a with C-a, it'll work (ctrl+a).
What am I doing wrong?
You can't and it's not a good idea, the shift key is by no way meant for that. Take a look in the man tmux, section KEY BINDINGS for the list of available keys. More info are available here https://unix.stackexchange.com/a/140010
Solution 1
Run: (WARN: Save your work in all sessions first)
tmux kill-server
Solution 2
In your .zshrc/.bashrc file, add the following line:
[ -z "${TMUX}" ] || tmux YOUR_COMMAND
e.g. YOUR_COMMAND = set -g prefix S-a.

tmux: allow-rename, but ALSO override?

I'd like to be able to issue a command like this:
tmux new-window -n irc ssh -t eco /usr/bin/weechat
and have the title of the new window be "irc". Instead, as soon as weechat launches, the title changes to weechat.
I had been under the impression based on the tmux man page that if you set a window title explicitly, automatic-rename would be disabled for you:
automatic-rename
[...] This flag is automatically disabled for an individual window when a
name is specified at creation with new-window or new-session, or later
with rename-window, or with a terminal escape sequence.
But that seems to not be the case. What am I missing here? I do want automatic-rename in most cases - I just want to also be able to specify -n windowname and have it take precedence.

Prevent tmux from displaying/replacing user-namespace from window's name

I would like to give fix name different tmux pane title but whenever I move to a different directory tmux just replace pane name that I have define with something like: 0:username#namespace:~/directory which confusing. Any help?
I found the answer here
The tmux command for this is:
set-option -g allow-rename off

Resources