Move Window Between Tmux Clients

How can I move a window to another session in tmux?

From my testing on tmux 2.6, you'll need two things for the command to move an entire window over:

  • The name of the session you want to move the window from (for future reference, $session_name)
  • The index of the window you want to move (in the session it's currently in, of course -- we'll call this $window_index). This is actually optional -- if you omit this, then it defaults to the window in focus in the session you're pulling the window from.

From this point, you can just change to the session you want to move the window into, <tmux-escape>: into a command prompt, and type a command of this form:

move-window -s $session_name[:$window_index]

...where, as noted before, the $window_index is optional (as indicated by the square brackets, which aren't actually part of the syntax
). To use some concrete examples:

move-window -s $session_name # Moves from currently-focused window from session named `$session_name` 

move-window -s $session_name:$window_index # Moves from window with index `$window_index` from session named `$session_name` into the current session

Et voilà! Your window got moved. :)

EDIT: Added some more info on an alternative that omits $window-index.

Move window between tmux clients

Yes, you can use the move-window command:

move-window [-d] [-s src-window] [-t dst-window]
(alias: movew)

This is similar to link-window, except the window at src-window is moved to dst-window.

where src-window and dst-window have the form: session:window.pane (session and window can be either name or id).

So, supposing you have an 'chat' session with an 'irc' window and want to move it to the 'other_session' session you can do (in the tmux prompt):

move-window -s chat:irc -t other_session

If you are already in the chat:irc window you don't need to specify the source so

move-window -t other_session:

will do it.

In the same way, from the 'other_session' session you don't need to specify the target.

movew -d irc:irc_window

If you haven't named you windows/sessions, you have to use their ids.

Moving between two seperate terminal/tmux windows

Command-backquote (-`) cycles through the open windows in Terminal.

tmux 1.7 move window

The documentation does not explicitly say this, but when you use -r, the argument to -t is interpreted as a session specifier, not a window specifier.

Thus, move-window -r -t 4 tells tmux to renumber all the windows in the session named/matching the string “4”.

It sounds like you can accomplish what you want* with two commands (assuming that you have base-index set to 1):

move-window -t 4 ; move-window -r

You can bind a sequence of commands to a key, but you need to escape the semicolon (so that the second command is not simply executed immediately after the initial bind command):

bind-key : move-window -t 4 \; move-window -r

Also, if you normally maintain a “gapless” sequence of window numbers (e.g. you have the renumber-windows option enabled), then you can replace the 4 with : and the command pair will work for any number of windows (not just 3 or fewer): : as a destination window specifier means “the first unused window number in the current session” (i.e. 4 if you already have windows 1–3).


* If I understand correctly that you want to transform a set of windows like 1:A, 2:B, 3:C to 1:B, 2:C, 3:A (i.e. move window #1 (“A”) to the end and renumber them all so that you have 1–3 again instead of 2–4).

Switch between sessions in tmux?

CTRL-b s

found it! Alex's answer is awesome as well. Note CTRL-b is my prefix, your prefix could be something else.

How to config tmux to move window lists from default bottom to top?

See this answer on Unix & Linux. If you build from SVN you can set the status bar on top with:

set-option -g status-position top

This will be included in tmux 1.7

how to move Tmux panes

There is probably an easier way, but what you can do is arrange the panes manually in each of the two configurations, noting each layout in a variable with e.g.:

layout1=$(tmux list-windows -F '#{window_layout}')

This holds a string something like:

5f2f,80x23,0,0[80x11,0,0,0,80x11,0,12{39x11,0,12,1,40x11,40,12,2}]

which you must not alter in any way as the first number is a checksum of the rest of the string.

Once you have the two strings you can set a binding to set that layout using select-layout, or by giving the command from the shell where you have the variables:

tmux select-layout "$layout1"

You might find it easier to write a small helper script, say mtmux to toggle between the layouts:

#!/usr/bin/bash
# https://stackoverflow.com/q/56343223/5008284
# toggle between 2 layouts, previously saved
layout1='5f2f,80x23,0,0[80x11,0,0,0,80x11,0,12{39x11,0,12,1,40x11,40,12,2}]'
layout2='093c,80x23,0,0{39x23,0,0[39x11,0,0,0,39x11,0,12,4],40x23,40,0,3}'
layout="$(tmux list-windows -F '#{window_layout}')"
case "$layout" in
*80x11*) new=$layout2 ;;
*) new=$layout1 ;;
esac
tmux select-layout "$new"
tmux display-panes
exit 0

and have a binding, say control-L, to run this shell:

    bind-key -n C-l run-shell 'mtmux'

How do i switch the active tmux session inside a shell script

There is no concept of a "selected session", clients have an attached session but outside tmux when you don't specify a session the choice of which to use is made separately each time. See here: https://github.com/tmux/tmux/wiki/Advanced-Use#the-default-target

But you shouldn't need it. You are already using -t to specify the window, use it to specify the session as well:

 tmux send-keys -t "$SESSION:8021" 'quit' C-m

You don't need select-window either unless you later plan to attach, and then one select-window at the end would do. See https://github.com/tmux/tmux/wiki/Advanced-Use#command-targets for a description of targets.

You may also find the has-session command useful instead of using grep, or the -F flag to list-sessions.



Related Topics



Leave a reply



Submit