From 89325d09822efb00b68653c24d1ed56abb20ce58 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Thu, 24 May 2012 00:28:56 +0100 Subject: [PATCH] Add new layout helper functions for pane creation and command execution --- lib/layout-helpers.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/lib/layout-helpers.sh b/lib/layout-helpers.sh index 7e136e4..6bc661d 100644 --- a/lib/layout-helpers.sh +++ b/lib/layout-helpers.sh @@ -21,6 +21,28 @@ new_window() { tmux new-window -t "$session:" "${winarg[@]}" "${command[@]}" } +# Split current window/pane vertically. +# +# Arguments: +# - $1: (optional) Percentage of frame the new pane will use. +# - $2: (optional) Target pane ID to split in current window. +# +split_v() { + if [ -n "$1" ]; then local percentage=(-p "$1"); fi + tmux split-window -t "$session:$window.$2" -v "${percentage[@]}" +} + +# Split current window/pane horizontally. +# +# Arguments: +# - $1: (optional) Percentage of frame the new pane will use. +# - $2: (optional) Target pane ID to split in current window. +# +split_h() { + if [ -n "$1" ]; then local percentage=(-p "$1"); fi + tmux split-window -t "$session:$window.$2" -h "${percentage[@]}" +} + # Select a specific window. # # Arguments: @@ -30,6 +52,26 @@ select_window() { tmux select-window -t "$session:$1" } +# Select a specific pane in the current window. +# +# Arguments: +# - $1: Pane ID to select. +# +select_pane() { + tmux select-pane -t "$session:$window.$1" +} + +# Runs a shell command in the currently active pane/window. +# +# Arguments: +# - $1: Shell command to run. +# - $2: (optional) Target pane ID to run command in. +# +run_cmd() { + tmux send-keys -t "$session:$window.$2" -l "$1" + tmux send-keys -t "$session:$window.$2" "C-m" +} + # Cusomize session root path. Default is `$HOME`. # # Arguments: