|
| 1 | +# Create a tmux layout for dev with editor, ai, and terminal |
| 2 | +tml() { |
| 3 | + [[ -z $TMUX ]] && { echo "You must start tmux to use tml."; return 1; } |
| 4 | + |
| 5 | + local current_dir="${PWD}" |
| 6 | + local editor_pane ai_pane |
| 7 | + local ai="$1" |
| 8 | + |
| 9 | + # Use TMUX_PANE for the pane we're running in (stable even if active window changes) |
| 10 | + editor_pane="$TMUX_PANE" |
| 11 | + |
| 12 | + # Name the current window after the base directory name |
| 13 | + tmux rename-window -t "$editor_pane" "$(basename "$current_dir")" |
| 14 | + |
| 15 | + # Split window vertically - top 85%, bottom 15% (target editor pane explicitly) |
| 16 | + tmux split-window -v -p 15 -t "$editor_pane" -c "$current_dir" |
| 17 | + |
| 18 | + # Split editor pane horizontally - AI on right 30% (capture new pane ID directly) |
| 19 | + ai_pane=$(tmux split-window -h -p 30 -t "$editor_pane" -c "$current_dir" -P -F '#{pane_id}') |
| 20 | + |
| 21 | + # Run ai in the right pane |
| 22 | + tmux send-keys -t "$ai_pane" "$ai" C-m |
| 23 | + |
| 24 | + # Run nvim in the left pane |
| 25 | + tmux send-keys -t "$editor_pane" "$EDITOR ." C-m |
| 26 | + |
| 27 | + # Select the nvim pane for focus |
| 28 | + tmux select-pane -t "$editor_pane" |
| 29 | +} |
| 30 | + |
| 31 | +# Create a tml window per subdirectory in the current directory |
| 32 | +tmlm() { |
| 33 | + [[ -z $TMUX ]] && { echo "You must start tmux to use tmlm."; return 1; } |
| 34 | + |
| 35 | + local ai="$1" |
| 36 | + local base_dir="$PWD" |
| 37 | + local first=true |
| 38 | + |
| 39 | + # Rename the session to the current directory name (replace dots/colons which tmux disallows) |
| 40 | + tmux rename-session "$(basename "$base_dir" | tr '.:' '--')" |
| 41 | + |
| 42 | + for dir in "$base_dir"/*/; do |
| 43 | + [[ -d $dir ]] || continue |
| 44 | + local dirpath="${dir%/}" |
| 45 | + |
| 46 | + if $first; then |
| 47 | + # Reuse the current window for the first project |
| 48 | + tmux send-keys -t "$TMUX_PANE" "cd '$dirpath' && tml $ai" C-m |
| 49 | + first=false |
| 50 | + else |
| 51 | + local pane_id=$(tmux new-window -c "$dirpath" -P -F '#{pane_id}') |
| 52 | + tmux send-keys -t "$pane_id" "tml $ai" C-m |
| 53 | + fi |
| 54 | + done |
| 55 | +} |
| 56 | + |
| 57 | +# Create a dev layout using tmux with editor, opencode, and terminal |
| 58 | +nic() { |
| 59 | + tml c |
| 60 | +} |
| 61 | + |
| 62 | +# Create a dev layout using tmux with editor, claude, and terminal |
| 63 | +nicx() { |
| 64 | + tml cx |
| 65 | +} |
| 66 | + |
| 67 | +# Create tml windows for each subdirectory using opencode |
| 68 | +nicm() { |
| 69 | + tmlm c |
| 70 | +} |
| 71 | + |
| 72 | +# Create tml windows for each subdirectory using claude |
| 73 | +nicxm() { |
| 74 | + tmlm cx |
| 75 | +} |
0 commit comments