Skip to content

Instantly share code, notes, and snippets.

@Sleepful
Last active July 2, 2023 05:47
Show Gist options
  • Save Sleepful/38778107163d2693a66a8d0b9cf3288b to your computer and use it in GitHub Desktop.
Save Sleepful/38778107163d2693a66a8d0b9cf3288b to your computer and use it in GitHub Desktop.
FZF to select tmux windows and move them to another session. You may select multiple windows.
# this in your tmux config
bind M run-shell "source ~/.tmux/functions.sh && move_windows"
# this inside ~/.tmux/functions.sh
#!/bin/bash
#
function move_windows() {
windows=$(
tmux list-windows -F "#{window_active} #{window_index} #{window_name}" | sort -r | awk '{print $2 " : " $3}' | fzf-tmux -p | awk '{print $1}' | sort -r
)
if [ -n "$windows" ]; then
session=$(tmux list-sessions -F '#{session_attached} #{session_name}' | sort -r | awk '{print $2}' | fzf-tmux -p | awk '{print $1}')
current_session=$(tmux display-message -p '#S')
echo $windows | xargs -n1 -I {i} tmux move-window -b -s "$current_session":{i} -t "$session":1
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment