Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions lib/layouts.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,24 @@ compute_total_panes() {
echo $total
}

# Prepend cd to project directory for every pane command
# Empty commands become "cd <dir>"
# Non-empty commands become "cd <dir> && <cmd>"
prepend_cd_to_commands() {
local project_dir=$1
shift
local -a cmds=("$@")
local -a result=()
for cmd in "${cmds[@]}"; do
if [[ -z "$cmd" ]]; then
result+=("cd ${(q)project_dir}")
else
result+=("cd ${(q)project_dir} && ${cmd}")
fi
done
PREPARED_COMMANDS=("${result[@]}")
}

# Validate layout spec
# Returns 0 if valid, 1 if invalid (with error message to stderr)
validate_layout() {
Expand Down Expand Up @@ -149,7 +167,16 @@ layout_hybrid() {
return 1
fi

run_layout "layout-hybrid" "${label}" "${reuse_window}" "${project_dir}" "${layout_spec}" "${tabs_count}" "${cmds[@]}"
# Pad commands to fill all pane slots across all tabs
local panes_per_tab
panes_per_tab=$(compute_total_panes "$layout_spec")
local total_slots=$((panes_per_tab * tabs_count))
while (( ${#cmds[@]} < total_slots )); do
cmds+=("")
done

prepend_cd_to_commands "${project_dir}" "${cmds[@]}"
run_layout "layout-hybrid" "${label}" "${reuse_window}" "${project_dir}" "${layout_spec}" "${tabs_count}" "${PREPARED_COMMANDS[@]}"
}

# Check for deprecated layout: tabs syntax
Expand Down Expand Up @@ -196,8 +223,15 @@ layout_dynamic() {
return 1
fi

# Pass commands directly in spatial order - AppleScript handles them inline
run_layout "layout-dynamic" "${label}" "${reuse_window}" "${project_dir}" "${layout_spec}" "${spatial_cmds[@]}"
# Pad commands to fill all pane slots
local total_panes
total_panes=$(compute_total_panes "$layout_spec")
while (( ${#spatial_cmds[@]} < total_panes )); do
spatial_cmds+=("")
done

prepend_cd_to_commands "${project_dir}" "${spatial_cmds[@]}"
run_layout "layout-dynamic" "${label}" "${reuse_window}" "${project_dir}" "${layout_spec}" "${PREPARED_COMMANDS[@]}"
}

# Run a layout script with progress dots
Expand Down
6 changes: 0 additions & 6 deletions scripts/layout-dynamic.applescript
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ on run argv
set frontmost to true
delay 0.5

-- cd to project directory (this is pane 1, spatial position 0)
set the clipboard to "cd " & (quoted form of projectDir) & " && clear"
keystroke "v" using {command down}
key code 36 -- Enter
delay 0.5

-- PHASE 1: Create row spine (n-1 vertical splits)
-- This creates one anchor pane per row
if numRows > 1 then
Expand Down
6 changes: 0 additions & 6 deletions scripts/layout-hybrid.applescript
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,6 @@ on run argv
-- cmdIndex = (tabIdx - 1) * panesPerTab + spatialIdx
set tabCmdBase to (tabIdx - 1) * panesPerTab

-- cd to project directory (this is pane 1 of current tab)
set the clipboard to "cd " & (quoted form of projectDir) & " && clear"
keystroke "v" using {command down}
key code 36 -- Enter
delay 0.5

-- === PHASE 1: Create row spine (n-1 vertical splits) ===
-- This creates one anchor pane per row
if numRows > 1 then
Expand Down