all repos

tmux-stare @ 66fb03a08c6a9c65ca7b8e2d8fc5b340564d3708

session manager, but my session manager
1 files changed, 23 insertions(+), 7 deletions(-)
feat: save/restore active pane per window and marked pane

Save #{window_active_pane_index} per window and #{pane_marked} per pane.
On restore, select each window's active pane and re-mark the marked pane.
Author: Oleksandr Smirnov olexsmir@gmail.com
Committed at: 2026-06-07 20:45:50 +0300
Authored at: 2026-06-07 20:42:50 +0300
Change ID: wuvxswxlrzwwmmwlxxzvlsvpxmqltlsx
Parent: 6071455
M scripts/sessions.sh
···
        42
        42
         save_windows() {

      
        43
        43
           local session_name="$1"

      
        44
        44
           local save_file="$2"

      
        45
        
        -  local format="window$S#{window_index}$S#{window_name}$S#{window_layout}$S#{window_active}$S#{?automatic-rename,on,off}"

      
        
        45
        +  local format="window$S#{window_index}$S#{window_name}$S#{window_layout}$S#{window_active}$S#{?automatic-rename,on,off}$S#{window_active_pane_index}"

      
        46
        46
           tmux list-windows -t "$session_name" -F "$format" >>"$save_file"

      
        47
        47
         }

      
        48
        48
         

      ···
        195
        195
         save_panes() {

      
        196
        196
           local session_name="$1"

      
        197
        197
           local save_file="$2"

      
        198
        
        -  local format="pane$S#{pane_index}$S#{pane_current_path}$S#{pane_active}$S#{window_index}$S#{pane_pid}$S#{pane_current_command}"

      
        
        198
        +  local format="pane$S#{pane_index}$S#{pane_current_path}$S#{pane_active}$S#{window_index}$S#{pane_pid}$S#{pane_current_command}$S#{pane_marked}"

      
        199
        199
           tmux list-panes -s -t "$session_name" -F "$format" |

      
        200
        200
             while IFS="$S" read -r line; do

      
        201
        201
               local command

      
        202
        
        -      IFS="$S" read -r _ _ _ _ _ pane_pid pane_current_command <<<"$line"

      
        
        202
        +      IFS="$S" read -r _ _ _ _ _ pane_pid pane_current_command pane_marked <<<"$line"

      
        203
        203
               command="$(capture_running_command "$pane_pid" "$pane_current_command")"

      
        204
        204
         

      
        205
        
        -      awk -v command="$command" \

      
        206
        
        -        'BEGIN {FS=OFS="\t"} {$6=command; NF=6; print}' \

      
        
        205
        +      awk -v command="$command" -v marked="$pane_marked" \

      
        
        206
        +        'BEGIN {FS=OFS="\t"} {$6=command; $7=marked; NF=7; print}' \

      
        207
        207
                 <<<"$line" >>"$save_file"

      
        208
        208
             done

      
        209
        209
         }

      ···
        330
        330
           local initial_window_restored=false

      
        331
        331
         

      
        332
        332
           declare -A window_layouts

      
        
        333
        +  declare -A window_active_panes

      
        333
        334
           declare active_window

      
        
        335
        +  declare marked_pane

      
        334
        336
           while read -r line; do

      
        335
        337
             case $line in

      
        336
        338
             window*)

      
        337
        
        -      IFS=$S read -r _ window_index window_name window_layout window_active auto_rename <<<"$line"

      
        
        339
        +      IFS=$S read -r _ window_index window_name window_layout window_active auto_rename window_active_pane_index <<<"$line"

      
        338
        340
               [[ -z "$auto_rename" ]] && auto_rename="on"

      
        339
        341
               window_id="$session_name:$window_index"

      
        340
        342
               tmux new-window -k -t "$window_id" -n "$window_name"

      ···
        349
        351
               if [[ "$window_active" == "1" ]]; then

      
        350
        352
                 active_window="$window_id"

      
        351
        353
               fi

      
        
        354
        +      if [[ -n "$window_active_pane_index" ]]; then

      
        
        355
        +        window_active_panes["$window_id"]="$window_active_pane_index"

      
        
        356
        +      fi

      
        352
        357
               ;;

      
        353
        358
         

      
        354
        359
             pane*)

      
        355
        
        -      IFS=$S read -r _ pane_index pane_current_path pane_active window_index command <<<"$line"

      
        
        360
        +      IFS=$S read -r _ pane_index pane_current_path pane_active window_index command pane_marked <<<"$line"

      
        356
        361
               if [[ "$pane_index" == "$(get_tmux_option base-index 0)" ]]; then

      
        357
        362
                 tmux send-keys -t "$session_name:$window_index" "cd \"$pane_current_path\"" Enter "clear" Enter

      
        358
        363
               else

      ···
        361
        366
               if [[ "$pane_active" == "1" ]]; then

      
        362
        367
                 tmux select-pane -t "$session_name:$window_index.$pane_index"

      
        363
        368
               fi

      
        
        369
        +      if [[ "$pane_marked" == "1" ]]; then

      
        
        370
        +        marked_pane="$session_name:$window_index.$pane_index"

      
        
        371
        +      fi

      
        364
        372
               if should_restore_command "$command"; then

      
        365
        373
                 tmux send-keys -t "$session_name:$window_index.$pane_index" "$command" Enter

      
        366
        374
               fi

      ···
        373
        381
           for window in "${!window_layouts[@]}"; do

      
        374
        382
             tmux select-layout -t "$window" "${window_layouts[$window]}"

      
        375
        383
           done

      
        
        384
        +

      
        
        385
        +  for window in "${!window_active_panes[@]}"; do

      
        
        386
        +    tmux select-pane -t "$window.${window_active_panes[$window]}"

      
        
        387
        +  done

      
        
        388
        +

      
        
        389
        +  if [[ -n "$marked_pane" ]]; then

      
        
        390
        +    tmux select-pane -m -t "$marked_pane"

      
        
        391
        +  fi

      
        376
        392
         

      
        377
        393
           tmux select-window -t "$active_window"

      
        378
        394
           tmux switch-client -t "$session_name"