diff --git a/tmux.conf b/tmux.conf index eb141d41..fd74be2e 100644 --- a/tmux.conf +++ b/tmux.conf @@ -77,11 +77,11 @@ bind h select-pane -L bind j select-pane -D bind k select-pane -U bind l select-pane -R -bind H run '~/.dotfiles/tmux/swap-pane.rb left' -bind J run '~/.dotfiles/tmux/swap-pane.rb down' -bind K run '~/.dotfiles/tmux/swap-pane.rb up' -bind L run '~/.dotfiles/tmux/swap-pane.rb right' -bind M run '~/.dotfiles/tmux/swap-pane.rb master' +bind H run '~/.dotfiles/tmux/swap-pane.sh left' +bind J run '~/.dotfiles/tmux/swap-pane.sh down' +bind K run '~/.dotfiles/tmux/swap-pane.sh up' +bind L run '~/.dotfiles/tmux/swap-pane.sh right' +bind M run '~/.dotfiles/tmux/swap-pane.sh master' bind o resize-pane -Z bind S choose-session diff --git a/tmux/swap-pane.sh b/tmux/swap-pane.sh new file mode 100755 index 00000000..92cf88c6 --- /dev/null +++ b/tmux/swap-pane.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +swap() { tmux swap-pane -s"$1" -t"$2"; } + +CONF=~/.tmux/lastpane + +target= +case $1 in + up) target="U" ;; + down) target="D" ;; + left) target="L" ;; + right) target="R" ;; + master) target="M" ;; + *) exit 1 ;; +esac + +src_pane=$(tmux display-message -p "#P") +tmux select-pane -${target} + +dst_pane=$(tmux display-message -p "#P") +tmux select-pane -${src_pane} + +if [[ "$target" == "M" ]]; then + dst_pane=0 +fi +swap "$src_pane" "$dst_pane" +tmux select-pane -t"$dst_pane"