From 8bad9472e8c69628169a1073444e4ff152f6ff4a Mon Sep 17 00:00:00 2001 From: David Chen Date: Sat, 25 Apr 2026 12:04:52 -0700 Subject: [PATCH] tmux config update --- .tmux.conf | 8 ++++---- tmux/scripts/layout_builder.sh | 33 +++++++++++++++------------------ 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/.tmux.conf b/.tmux.conf index abf88d8..16a661e 100644 --- a/.tmux.conf +++ b/.tmux.conf @@ -246,10 +246,10 @@ bind -n M-y next-window bind -n M-L run-shell "bash ~/.config/tmux/scripts/swap_window_in_session.sh left" bind -n M-Y run-shell "bash ~/.config/tmux/scripts/swap_window_in_session.sh right" -bind I run-shell "~/.config/tmux/scripts/layout_builder.sh right" -bind N run-shell "~/.config/tmux/scripts/layout_builder.sh left" -bind U run-shell "~/.config/tmux/scripts/layout_builder.sh up" -bind E run-shell "~/.config/tmux/scripts/layout_builder.sh down" +bind I run-shell "~/.config/tmux/scripts/layout_builder.sh right '#{pane_current_path}'" +bind N run-shell "~/.config/tmux/scripts/layout_builder.sh left '#{pane_current_path}'" +bind U run-shell "~/.config/tmux/scripts/layout_builder.sh up '#{pane_current_path}'" +bind E run-shell "~/.config/tmux/scripts/layout_builder.sh down '#{pane_current_path}'" # -- toggle_syn_input bind C-g if-shell '[[ $(tmux showw synchronize-panes | cut -d\ -f2) == "on" ]]' \ diff --git a/tmux/scripts/layout_builder.sh b/tmux/scripts/layout_builder.sh index 7cf6135..01475b5 100755 --- a/tmux/scripts/layout_builder.sh +++ b/tmux/scripts/layout_builder.sh @@ -1,12 +1,19 @@ #!/usr/bin/env bash set -euo pipefail -if [ $# -ne 1 ]; then - tmux display-message "layout command requires direction" +if [ $# -ne 2 ]; then + tmux display-message "layout command requires direction and path" exit 1 fi dir="$1" +target_path="$2" + +if [[ -z "$target_path" || ! -d "$target_path" ]]; then + target_path="$HOME" +fi + +printf -v start_cmd 'cd %q && exec ${SHELL:-/bin/zsh} -l' "$target_path" run_tmux() { local output @@ -18,23 +25,21 @@ run_tmux() { } pane_count=0 -while IFS='|' read -r pid ptop pleft ppath; do +while IFS='|' read -r pid ptop pleft; do case $pane_count in 0) id1=$pid top1=$ptop left1=$pleft - path1=$ppath ;; 1) id2=$pid top2=$ptop left2=$pleft - path2=$ppath ;; esac pane_count=$((pane_count + 1)) -done < <(tmux list-panes -F "#{pane_id}|#{pane_top}|#{pane_left}|#{pane_current_path}") +done < <(tmux list-panes -F "#{pane_id}|#{pane_top}|#{pane_left}") if [ "$pane_count" -ne 2 ]; then tmux display-message "layout-${dir} expects exactly 2 panes" @@ -43,26 +48,18 @@ fi if [ "$top1" -le "$top2" ]; then top_id=$id1 - top_path=$path1 bottom_id=$id2 - bottom_path=$path2 else top_id=$id2 - top_path=$path2 bottom_id=$id1 - bottom_path=$path1 fi if [ "$left1" -le "$left2" ]; then left_id=$id1 - left_path=$path1 right_id=$id2 - right_path=$path2 else left_id=$id2 - left_path=$path2 right_id=$id1 - right_path=$path1 fi ensure_horizontal() { @@ -74,12 +71,12 @@ ensure_horizontal() { case "$dir" in right) - new_id=$(run_tmux split-window -P -F '#{pane_id}' -h -c "$top_path" -t "$top_id") + new_id=$(run_tmux split-window -P -F '#{pane_id}' -h -c "$target_path" -t "$top_id" "$start_cmd") run_tmux join-pane -v -s "$bottom_id" -t "$top_id" run_tmux select-pane -t "$new_id" ;; left) - new_id=$(run_tmux split-window -P -F '#{pane_id}' -h -b -c "$top_path" -t "$top_id") + new_id=$(run_tmux split-window -P -F '#{pane_id}' -h -b -c "$target_path" -t "$top_id" "$start_cmd") run_tmux join-pane -v -s "$bottom_id" -t "$top_id" run_tmux select-pane -t "$new_id" ;; @@ -87,7 +84,7 @@ case "$dir" in ensure_horizontal run_tmux break-pane -d -s "$right_id" run_tmux select-pane -t "$left_id" - new_id=$(run_tmux split-window -P -F '#{pane_id}' -v -b -c "$left_path" -t "$left_id") + new_id=$(run_tmux split-window -P -F '#{pane_id}' -v -b -c "$target_path" -t "$left_id" "$start_cmd") run_tmux join-pane -h -s "$right_id" -t "$left_id" run_tmux select-pane -t "$new_id" ;; @@ -95,7 +92,7 @@ case "$dir" in ensure_horizontal run_tmux break-pane -d -s "$right_id" run_tmux select-pane -t "$left_id" - new_id=$(run_tmux split-window -P -F '#{pane_id}' -v -c "$left_path" -t "$left_id") + new_id=$(run_tmux split-window -P -F '#{pane_id}' -v -c "$target_path" -t "$left_id" "$start_cmd") run_tmux join-pane -h -s "$right_id" -t "$left_id" run_tmux select-pane -t "$new_id" ;;