222

How do I rename a pane in tmux?

Mateen Ulhaq
  • 24,552
  • 19
  • 101
  • 135
ovolax
  • 2,387
  • 2
  • 12
  • 7

9 Answers9

350

Renaming a window

Ctrl-b ,

where Ctrl-b is the default prefix key.

Alternatively, run:

tmux rename-window <new name>

Or type Ctrl-b : rename-window <new name>.


Renaming a pane

In newer versions you can rename pane using:

tmux select-pane -T <title>

Or type Ctrl-b : select-pane -T <pane_name>.

Also, I have the following two lines in ~/.tmux.conf, in order to view the title of the pane in the top of the pane itself, and reformat the title.

set -g pane-border-status top

set -g pane-border-format " [ ###P #T ] "

Life5ign
  • 192
  • 11
idej
  • 5,034
  • 1
  • 11
  • 14
  • When I am renaming current window, I can not see what I am typing, is that by default? Or is it due to my configuration? Although I think my configuration is not preventing `tmux` from showing that. – zyy Feb 05 '19 at 17:23
  • 1
    To clarify, you _can_ rename a pane, and this is needed when accidentally binary output corrupts it. @Mapad's answer resolves this. – fuzzyTew Jun 06 '19 at 17:41
  • that gets reverted back whenever you `ls` – anilbey Aug 28 '19 at 14:59
  • 4
    @anilbey Same here. The solution to that is [`set-option -g allow-rename off`](https://stackoverflow.com/a/34004541/99777) – joeytwiddle Aug 29 '19 at 06:43
  • This is useful, but it renames a window, not a pane. – AtomHeartFather Jun 02 '21 at 08:50
  • it works on bash, but not on zsh for some reason. Any idea? – A1m Mar 01 '23 at 17:15
59

yes you can rename pane names, and not only window names starting with tmux >= 2.3. Just type the following in your shell:

printf '\033]2;%s\033\\' 'title goes here'

you might need to add the following to your .tmux.conf to display pane names:

# Enable names for panes
set -g pane-border-status top

you can also automatically assign a name:

set -g pane-border-format "#P: #{pane_current_command}"
Mapad
  • 8,407
  • 5
  • 41
  • 40
  • 1
    Is there a way to put args of a command into pane border format? Oh, there is a corresponding [issue](https://github.com/tmux/tmux/issues/733) on github. – konstunn Aug 29 '18 at 06:18
  • title length is 21 – Smart Manoj Apr 03 '22 at 01:54
  • I tried your answer and it works for a brief second but then automatically renames to my home directory. I tried adding `setw -g automatic-rename off` but no luck. – Elijah Lynn Nov 18 '22 at 21:11
26

For those scripting tmux, there is a command called rename-window so e.g.

tmux rename-window -t <window> <newname>
DenLilleMand
  • 3,732
  • 5
  • 25
  • 34
13

For those who want to easily rename their panes in a bash shell, this is what I have in my .tmux.conf

set -g default-command '                      \
function renamePane () {                      \
  read -p "Enter Pane Name: " pane_name;      \
  printf "\033]2;%s\033\\r:r" "${pane_name}"; \
};                                            \
export -f renamePane;                         \
bash -i'
set -g pane-border-status top
set -g pane-border-format "#{pane_index} #T #{pane_current_command}"
bind-key -T prefix R send-keys "renamePane" C-m

Panes are automatically named with their index, machine name and current command. To change the machine name you can run <C-b>R which will prompt you to enter a new name.

*Pane renaming only works when you are in a shell.

raman
  • 643
  • 7
  • 16
  • Be very careful with this. This screwed my tmux when I (?) id this incorrectly. Even though I could not find the renamePane function in any dotfiles, it persisted an error when starting tmux: "zsh:export:1: invalid option(s)". A reboot fixed this. – ProfessorKaos64 Jan 26 '22 at 16:50
  • Sorry, I haven't tested this on zsh, only bash shells. – raman Jan 27 '22 at 17:13
5

Also when scripting, you can specify a name when creating the window with -n <window name>. For example:

# variable to store the session name
SESSION="my_session"

# set up session
tmux -2 new-session -d -s $SESSION

# create window; split into panes
tmux new-window -t $SESSION:0 -n 'My Window with a Name'
rotarydial
  • 2,181
  • 2
  • 23
  • 27
5

The easiest option for me was to rename the title of the terminal instead. Please see: https://superuser.com/questions/362227/how-to-change-the-title-of-the-mintty-window

In this answer, they mention to modify the PS1 variable. Note: my situation was particular to cygwin.

TL;DR Put this in your .bashrc file:

function settitle() {
      export PS1="\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n$ "
      echo -ne "\e]0;$1\a"
}

Put this in your .tmux.conf file, or similar formatting:

set -g pane-border-status bottom
set -g pane-border-format "#P #T #{pane_current_command}"

Then you can change the title of the pane by typing this in the console:

settitle titlename
Todd
  • 305
  • 2
  • 9
5

You can adjust the pane title by setting the pane border in the tmux.conf for example like this:

###############
# pane border #
###############
set -g pane-border-status bottom
#colors for pane borders
setw -g pane-border-style fg=green,bg=black
setw -g pane-active-border-style fg=colour118,bg=black
setw -g automatic-rename off
setw -g pane-border-format ' #{pane_index} #{pane_title} : #{pane_current_path} '
# active pane normal, other shaded out​
setw -g window-style fg=colour28,bg=colour16
setw -g window-active-style fg=colour46,bg=colour16

Where pane_index, pane_title and pane_current_path are variables provided by tmux itself.

After reloading the config or starting a new tmux session, you can then set the title of the current pane like this:

tmux select-pane -T "fancy pane title";
#or
tmux select-pane -t paneIndexInteger -T "fancy pane title";

If all panes have some processes running, so you can't use the command line, you can also type the commands after pressing the prefix bind (C-b by default) and a colon (:) without having "tmux" in the front of the command:

select-pane -T "fancy pane title"
#or:
select-pane -t paneIndexInteger -T "fancy pane title"
FullStack Alex
  • 1,783
  • 19
  • 31
  • This mostly works for me, and the rename works and the placement is good. But then when I run another command, it still auto-renames the pane to something else. I am running fish inside, maybe there is something up with that. – Elijah Lynn Nov 18 '22 at 21:07
  • I did kill the entire `tmux` process just to make sure config reloaded too. reloading it wasn't enough, as I was still seeing pane titles after I commented it out and reloaded. – Elijah Lynn Nov 18 '22 at 21:19
  • @ElijahLynn I have this custom keybinding defined in my tmux.conf for renaming pane titles on pressing Alt+P and it works just fine regardless of any running process in the shell: `bind-key -n M-p command-prompt "set -p @custom_pane_title '%%'"`. Hope that helps. – FullStack Alex Nov 18 '22 at 21:56
  • Thanks, I added your binding and when I press `alt + p` I get a `(set)` in the bottom bar that accepts text input and when I press return it disappears and nothing happens. I'll keep tinkering with it. It must be something in my config, I think. – Elijah Lynn Nov 19 '22 at 03:02
2

I use byobu with tmux as backend and would like to provide an alternative way: If you have Mouse-Mode on (for me Alt+F12), you can just right click onto the pane and select Rename. It appears that you can only rename the currently selected pane.

enter image description here

John
  • 1,472
  • 1
  • 19
  • 22
0

To rename the pane, write the following in the tmux command prompt:

select-pane -T 'NEW PANE NAME'

To bind it to a key (example: u) write the following in your ~/.tmux.conf file:

bind u command-prompt "select-pane -T '%%'"

Then you can rename the pane just by <prefix>u

FYI:

  • To open the command prompt you need to <prefix>:
  • <prefix> is C-b by default (it can be changed with a set -g prefix NEW_KEY)
Juan
  • 463
  • 5
  • 10