From 8ef7f3e62f1029a1916f4aed614806c419ef298f Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Wed, 23 Dec 2015 02:39:04 -0500 Subject: [PATCH] tmux: add swap-pane.sh (ported from ruby) --- tmux.conf | 10 +++++----- tmux/swap-pane.sh | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) create mode 100755 tmux/swap-pane.sh 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"