1 files changed,
23 insertions(+),
27 deletions(-)
Author:
Oleksandr Smirnov
olexsmir@gmail.com
Committed at:
2026-06-07 19:09:54 +0300
Authored at:
2026-06-07 19:01:55 +0300
Change ID:
mvzslltzrylxnvnqkpslzmzmrvksuqsw
Parent:
b9948f1
M
scripts/sessions.sh
··· 6 6 7 7 # === common 8 8 get_current_session_name() { 9 - if [ "$(tmux display-message -p "#{session_grouped}")" = 0 ]; then 10 - tmux display-message -p "#{session_name}" 2>/dev/null || true 11 - else 12 - tmux display-message -p "#{session_group}" 2>/dev/null || true 13 - fi 9 + tmux display-message -p -F '#{?#{session_grouped},#{session_group},#{session_name}}' 14 10 } 15 11 16 12 rename_session() { ··· 46 42 save_windows() { 47 43 local session_name="$1" 48 44 local save_file="$2" 49 - local format="window$S#{window_index}$S#{window_name}$S#{window_layout}$S#{window_active}" 50 - tmux list-windows -t "$session_name" -F "$format" | while IFS="$S" read -r line; do 51 - IFS="$S" read -r _ window_index _ _ _ <<<"$line" 52 - local auto_rename 53 - auto_rename="$(tmux show-window-options -v -t "$session_name:$window_index" automatic-rename 2>/dev/null)" 54 - printf "%s%s%s\n" "$line" "$S" "${auto_rename:-on}" 55 - done >>"$save_file" 45 + local format="window$S#{window_index}$S#{window_name}$S#{window_layout}$S#{window_active}$S#{?automatic-rename,on,off}" 46 + tmux list-windows -t "$session_name" -F "$format" >>"$save_file" 56 47 } 57 48 58 49 format_process_command() { ··· 103 94 104 95 select_active_command_pid() { 105 96 local pane_pid="$1" 106 - local pane_target="$2" 107 - local pane_current_command 97 + local pane_current_command="$2" 108 98 local pids 109 99 local pid 110 100 local name ··· 112 102 local fallback_pid="" 113 103 local descendant_count=0 114 104 115 - pane_current_command="$(tmux display-message -p -t "$pane_target" "#{pane_current_command}" 2>/dev/null)" 116 105 pids="$(get_descendant_pids "$pane_pid")" 117 106 118 107 for pid in $pids; do ··· 151 140 152 141 capture_running_command() { 153 142 local pane_pid="$1" 154 - local pane_target="$2" 143 + local pane_current_command="$2" 155 144 local command_pid 156 145 157 - command_pid="$(select_active_command_pid "$pane_pid" "$pane_target")" 146 + command_pid="$(select_active_command_pid "$pane_pid" "$pane_current_command")" 158 147 [[ -n "$command_pid" ]] || return 1 159 148 160 149 local pgid ··· 165 154 return 166 155 fi 167 156 157 + local descendants 158 + descendants="$(get_descendant_pids "$pane_pid")" 159 + 160 + local -A pid_pgid 161 + if [[ -n "$descendants" ]]; then 162 + while read -r p pg; do 163 + [[ -n "$p" ]] && pid_pgid["$p"]="$pg" 164 + done < <(ps -o pid=,pgid= -p $(echo "$descendants" | tr '\n' ' ') 2>/dev/null) 165 + fi 166 + 168 167 local pipeline_pids="" 169 - local pid pid_pgid 170 - for pid in $(get_descendant_pids "$pane_pid"); do 171 - pid_pgid="$(ps -o pgid= -p "$pid" 2>/dev/null | tr -d ' ')" 172 - [[ "$pid_pgid" == "$pgid" ]] || continue 168 + local pid 169 + for pid in $descendants; do 170 + [[ "${pid_pgid[$pid]:-}" == "$pgid" ]] || continue 173 171 pipeline_pids+=" $pid" 174 172 done 175 173 ··· 197 195 save_panes() { 198 196 local session_name="$1" 199 197 local save_file="$2" 200 - local format="pane$S#{pane_index}$S#{pane_current_path}$S#{pane_active}$S#{window_index}$S#{pane_pid}" 198 + local format="pane$S#{pane_index}$S#{pane_current_path}$S#{pane_active}$S#{window_index}$S#{pane_pid}$S#{pane_current_command}" 201 199 tmux list-panes -s -t "$session_name" -F "$format" | 202 200 while IFS="$S" read -r line; do 203 - local pane_target 204 201 local command 205 - IFS="$S" read -r _ pane_index _ _ window_index pane_pid <<<"$line" 206 - pane_target="${session_name}:${window_index}.${pane_index}" 207 - command="$(capture_running_command "$pane_pid" "$pane_target")" 202 + IFS="$S" read -r _ _ _ _ _ pane_pid pane_current_command <<<"$line" 203 + command="$(capture_running_command "$pane_pid" "$pane_current_command")" 208 204 209 205 awk -v command="$command" \ 210 - 'BEGIN {FS=OFS="\t"} {$6=command; print}' \ 206 + 'BEGIN {FS=OFS="\t"} {$6=command; NF=6; print}' \ 211 207 <<<"$line" >>"$save_file" 212 208 done 213 209 }