all repos

tmux-stare @ 6071455

session manager, but my session manager
3 files changed, 43 insertions(+), 43 deletions(-)
shfmt -w -i 2 .
Author: Oleksandr Smirnov olexsmir@gmail.com
Committed at: 2026-06-07 20:45:50 +0300
Authored at: 2026-06-07 19:08:49 +0300
Change ID: toyruzvuuuwutwlomwynkzormrlqkttr
Parent: bc69f2c
M prune.sh
···
        29
        29
           if [[ -v ACTIVE["$name"] ]]; then

      
        30
        30
             # Active session: keep the _last target always, prune old others

      
        31
        31
             target="$(readlink "$name"_last 2>/dev/null || true)"

      
        32
        
        -    if [ "$f" = "$target" ]; then continue; fi  # always keep the _last target

      
        
        32
        +    if [ "$f" = "$target" ]; then continue; fi # always keep the _last target

      
        33
        33
             if [[ "$ts" < "$CUTOFF" ]]; then

      
        34
        34
               rm "$f"

      
        35
        35
               echo "pruned: $f"

      
M scripts/helpers.sh
···
        38
        38
         ignored_session() {

      
        39
        39
           local name="$1"

      
        40
        40
           local ignores

      
        41
        
        -  IFS=' ' read -ra ignores <<< "$(get_opt_ignore)"

      
        
        41
        +  IFS=' ' read -ra ignores <<<"$(get_opt_ignore)"

      
        42
        42
           local i

      
        43
        43
           for i in "${ignores[@]}"; do

      
        44
        44
             [[ "$name" == "$i" ]] && return 0

      
M scripts/sessions.sh
···
        205
        205
               awk -v command="$command" \

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

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

      
        208
        
        -      done

      
        
        208
        +    done

      
        209
        209
         }

      
        210
        210
         

      
        211
        211
         link_session_last() {

      ···
        239
        239
         

      
        240
        240
         save_all_sessions() {

      
        241
        241
           tmux list-sessions -F "#{session_name} #{status}" | while read -r session status_val; do

      
        242
        
        -  [[ "$status_val" == "off" ]] && continue

      
        243
        
        -  ignored_session "$session" && continue

      
        244
        
        -  save_session "$session"

      
        245
        
        -done

      
        
        242
        +    [[ "$status_val" == "off" ]] && continue

      
        
        243
        +    ignored_session "$session" && continue

      
        
        244
        +    save_session "$session"

      
        
        245
        +  done

      
        246
        246
         

      
        247
        
        -local current_session="$(get_current_session_name)"

      
        248
        
        -if [[ -n "$current_session" ]]; then

      
        249
        
        -  link_last "$(get_opt_dir)/${current_session}_last" "$(get_opt_dir)"

      
        250
        
        -fi

      
        
        247
        +  local current_session="$(get_current_session_name)"

      
        
        248
        +  if [[ -n "$current_session" ]]; then

      
        
        249
        +    link_last "$(get_opt_dir)/${current_session}_last" "$(get_opt_dir)"

      
        
        250
        +  fi

      
        251
        251
         

      
        252
        
        -update_session_map

      
        
        252
        +  update_session_map

      
        253
        253
         }

      
        254
        254
         

      
        255
        255
         unload_session() {

      ···
        333
        333
           declare active_window

      
        334
        334
           while read -r line; do

      
        335
        335
             case $line in

      
        336
        
        -      window*)

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

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

      
        339
        
        -        window_id="$session_name:$window_index"

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

      
        341
        
        -        if [[ "$auto_rename" == "off" ]]; then

      
        342
        
        -          tmux set-window-option -t "$window_id" automatic-rename off

      
        343
        
        -          tmux rename-window -t "$window_id" "$window_name"

      
        344
        
        -        else

      
        345
        
        -          tmux set-window-option -t "$window_id" automatic-rename on

      
        346
        
        -        fi

      
        347
        
        -        [[ "$window_index" == "$initial_window_index" ]] && initial_window_restored=true

      
        348
        
        -        window_layouts["$window_id"]="$window_layout"

      
        349
        
        -        if [[ "$window_active" == "1" ]]; then

      
        350
        
        -          active_window="$window_id"

      
        351
        
        -        fi

      
        352
        
        -        ;;

      
        
        336
        +    window*)

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

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

      
        
        339
        +      window_id="$session_name:$window_index"

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

      
        
        341
        +      if [[ "$auto_rename" == "off" ]]; then

      
        
        342
        +        tmux set-window-option -t "$window_id" automatic-rename off

      
        
        343
        +        tmux rename-window -t "$window_id" "$window_name"

      
        
        344
        +      else

      
        
        345
        +        tmux set-window-option -t "$window_id" automatic-rename on

      
        
        346
        +      fi

      
        
        347
        +      [[ "$window_index" == "$initial_window_index" ]] && initial_window_restored=true

      
        
        348
        +      window_layouts["$window_id"]="$window_layout"

      
        
        349
        +      if [[ "$window_active" == "1" ]]; then

      
        
        350
        +        active_window="$window_id"

      
        
        351
        +      fi

      
        
        352
        +      ;;

      
        353
        353
         

      
        354
        
        -      pane*)

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

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

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

      
        358
        
        -        else

      
        359
        
        -          tmux split-window -d -t "$session_name:$window_index" -c "$pane_current_path"

      
        360
        
        -        fi

      
        361
        
        -        if [[ "$pane_active" == "1" ]]; then

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

      
        363
        
        -        fi

      
        364
        
        -        if should_restore_command "$command"; then

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

      
        366
        
        -        fi

      
        367
        
        -        ;;

      
        
        354
        +    pane*)

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

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

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

      
        
        358
        +      else

      
        
        359
        +        tmux split-window -d -t "$session_name:$window_index" -c "$pane_current_path"

      
        
        360
        +      fi

      
        
        361
        +      if [[ "$pane_active" == "1" ]]; then

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

      
        
        363
        +      fi

      
        
        364
        +      if should_restore_command "$command"; then

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

      
        
        366
        +      fi

      
        
        367
        +      ;;

      
        368
        368
             esac

      
        369
        369
           done

      
        370
        370