diff options
Diffstat (limited to 'dotfiles/common/.local/bin')
| -rwxr-xr-x | dotfiles/common/.local/bin/aix | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/dotfiles/common/.local/bin/aix b/dotfiles/common/.local/bin/aix index 9f689eb..0800cc1 100755 --- a/dotfiles/common/.local/bin/aix +++ b/dotfiles/common/.local/bin/aix @@ -31,6 +31,29 @@ build_candidates() { fi } +# Sort windows alphabetically by name, shells last +sort_windows() { + local windows shells projects sorted + windows=$(tmux list-windows -t "$SESSION" -F '#{window_name}'$'\t''#{window_id}') + shells=$(echo "$windows" | grep -iE '^(bash|zsh|fish|sh)'$'\t' | sort -t$'\t' -k1,1f) + projects=$(echo "$windows" | grep -viE '^(bash|zsh|fish|sh)'$'\t' | sort -t$'\t' -k1,1f) + sorted=$(printf '%s\n' "$projects" "$shells" | sed '/^$/d') + + # Move all to high temp indices to avoid collisions + local i=900 + while IFS=$'\t' read -r _name wid; do + tmux move-window -s "$wid" -t "$SESSION:$i" + ((i++)) + done <<<"$sorted" + + # Move to final sequential positions + i=1 + while IFS=$'\t' read -r _name wid; do + tmux move-window -s "$wid" -t "$SESSION:$i" + ((i++)) + done <<<"$sorted" +} + # If session exists, add new windows to it if tmux has-session -t "$SESSION" 2>/dev/null; then # Get existing window names to filter duplicates @@ -68,6 +91,7 @@ if tmux has-session -t "$SESSION" 2>/dev/null; then [ -z "$first_wid" ] && first_wid="$wid" done + sort_windows tmux select-window -t "$first_wid" fi fi @@ -108,8 +132,9 @@ for entry in "${selected[@]:1}"; do tmux send-keys -t "$wid" "$AI_CMD \"$AI_INSTRUCTIONS\"" Enter done -# Select first window and attach or switch -tmux select-window -t "$first_wid" +# Sort windows and select first +sort_windows +tmux select-window -t "$SESSION:1" if [ -n "$TMUX" ]; then tmux switch-client -t "$SESSION" else |
