diff options
| author | Craig Jennings <c@cjennings.net> | 2026-02-10 12:53:00 -0600 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-02-10 12:53:00 -0600 |
| commit | f5a1aa6d55772aa886dcaa29e9b44118e9e37e37 (patch) | |
| tree | 76dcc69aaec366f54231e0596822ae345b013c1b | |
| parent | 24e992246ddcdf4daf9fafc4e32dabe7e4cb31ef (diff) | |
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.
| -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 |
