From f5a1aa6d55772aa886dcaa29e9b44118e9e37e37 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Tue, 10 Feb 2026 12:53:00 -0600 Subject: feat(aix): sort windows alphabetically, shells last, start from 1 Windows are reordered after creation and when adding to an existing session. Shell windows (bash/zsh) sort to the end. Window numbering starts at 1. Focus lands on the first selected window. --- dotfiles/common/.local/bin/aix | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'dotfiles') 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 -- cgit v1.2.3