From 6d60e1482429b3629e97545f17f26c344ceb2737 Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Wed, 28 Feb 2024 12:56:42 +0100 Subject: [PATCH] tmux: Use move-window for window dragging Use move-window for window dragging instead of a loop and swap-window. When using -a or -b (i.e. after or before) the target can be occupied and the windows are reordered automatically. --- .config/tmux/tmux.conf | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/.config/tmux/tmux.conf b/.config/tmux/tmux.conf index 84d939d..f80d123 100644 --- a/.config/tmux/tmux.conf +++ b/.config/tmux/tmux.conf @@ -80,8 +80,7 @@ bind -r C-p prev bind -r N swap-window -d -t :+1 bind -r P swap-window -d -t :-1 -# Reorder windows by dragging on status line. This uses a loop and swap-window -# as move-window needs the target index to be free. +# Reorder windows by dragging on status line. # NOTE: This breaks the stack and last-used window. bind -n MouseDragEnd1Status { # TODO: Can we somehow get the idx of {mouse} without selecting it? @@ -90,17 +89,14 @@ bind -n MouseDragEnd1Status { set -F @target_idx "#{window_index}" if -F "#{!=:#{@source_idx},#{window_index}}" { select-window -t! } - # Get the right direction to not mess up the order when wrapping around - tmux_move_direction="#{?#{e|<:#{@target_idx},#{@source_idx}},:-1,:+1}" - tmux_move_target_idx="#{@target_idx}" + # Depending on the direction the window must be placed before or after + # the target + tmux_move_direction="#{?#{e|<:#{@target_idx},#{@source_idx}},-b,-a}" - run-shell "\ - while [ $tmux_move_target_idx -ne $(tmux display -a | grep -Po '(?<=^window_index=)[0-9]*') ]; do \ - tmux swap-window -d -t $tmux_move_direction; \ - done" + # NOTE: uses run-shell so the flag can be passed through a variable + run-shell "tmux move-window -t #{@target_idx} $tmux_move_direction" setenv -u tmux_move_direction - setenv -u tmux_move_target_idx } # TODO: Move to beginning or end like in MouseDragEnd1Status