diff options
Diffstat (limited to 'dotfiles')
| -rwxr-xr-x | dotfiles/common/.local/bin/aix | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/dotfiles/common/.local/bin/aix b/dotfiles/common/.local/bin/aix index b9d9e69..ad40d84 100755 --- a/dotfiles/common/.local/bin/aix +++ b/dotfiles/common/.local/bin/aix @@ -57,15 +57,35 @@ build_candidates() { fi } -# Sort windows: shells at base-index, projects alphabetically after +# Sort windows: non-project windows at base-index, projects alphabetically after sort_windows() { - local windows shells projects base_idx + local windows others projects base_idx project_names base_idx=$(tmux show-option -gv base-index 2>/dev/null || echo 0) 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) + + # Build list of known project basenames from candidate directories + build_candidates + project_names="" + for c in "${candidates[@]}"; do + project_names+="$(basename "${c/#\~/$HOME}")"$'\n' + done + + # Classify: windows matching a project basename are projects, rest are non-project + others="" + projects="" + while IFS=$'\t' read -r wname wid; do + [ -z "$wname" ] && continue + if echo "$project_names" | grep -qxF "$wname"; then + projects+="${wname}"$'\t'"${wid}"$'\n' + else + others+="${wname}"$'\t'"${wid}"$'\n' + fi + done <<<"$windows" + others=$(echo -n "$others" | sort -t$'\t' -k1,1f) + projects=$(echo -n "$projects" | sort -t$'\t' -k1,1f) + local all - all=$(printf '%s\n' "$shells" "$projects" | sed '/^$/d') + all=$(printf '%s\n' "$others" "$projects" | sed '/^$/d') # Move all to high temp indices to avoid collisions local i=900 @@ -74,13 +94,13 @@ sort_windows() { ((i++)) done <<<"$all" - # Place shells at base-index, projects contiguously after + # Place non-project windows at base-index, projects contiguously after i=$base_idx - if [ -n "$shells" ]; then + if [ -n "$others" ]; then while IFS=$'\t' read -r _name wid; do tmux move-window -s "$wid" -t "$SESSION:$i" ((i++)) - done <<<"$shells" + done <<<"$others" fi if [ -n "$projects" ]; then while IFS=$'\t' read -r _name wid; do |
