diff --git a/.config/tmux/tmux.conf b/.config/tmux/tmux.conf index aa4dfdc..ce4ebd2 100644 --- a/.config/tmux/tmux.conf +++ b/.config/tmux/tmux.conf @@ -80,6 +80,32 @@ 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. +# NOTE: This breaks the stack and last-used window. +bind -n MouseDragEnd1Status { + # TODO: Can we somehow get the idx of {mouse} without selecting it? + set -F @source_idx "#{window_index}" + select-window -t= + 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}" + + 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" + + setenv -u tmux_move_direction + setenv -u tmux_move_target_idx +} + +# TODO: Move to beginning or end like in MouseDragEnd1Status +# bind -n MouseDragEnd1StatusDefault display-message "#{e|>|f|0:#{mouse_x},#{e|/|f:213,2}}" + # Repeatable window-movement bindings bind -r \{ swap-pane -U bind -r \} swap-pane -D