all repos

tmux-stare @ 0471e155d021d674189d4c7a1388857b518b3972

session manager, but my session manager
2 files changed, 41 insertions(+), 32 deletions(-)
clanker did some fixes
Author: Oleksandr Smirnov olexsmir@gmail.com
Committed at: 2026-05-31 11:27:52 +0300
Authored at: 2026-05-06 14:22:52 +0300
Change ID: noqslzuznqylponqmlvpyqztmxvktwrq
Parent: 4443c84
M scripts/helpers.sh
···
        23
        23
         get_opt_last() { get_tmux_option "@stare-last" "0"; }

      
        24
        24
         set_opt_last() { set_tmux_option "@stare-last" "$1"; }

      
        25
        25
         get_opt_initialized() { get_tmux_option "@stare-initialized" "0"; }

      
        26
        
        -set_opt_initialized() { get_tmux_option "@stare-initialized" "$1"; }

      
        
        26
        +set_opt_initialized() { set_tmux_option "@stare-initialized" "$1"; }

      
        27
        27
         get_opt_save() { get_tmux_option "@stare-save" "C-s"; }

      
        28
        28
         get_opt_pick() { get_tmux_option "@stare-pick" ""; }

      
        29
        29
         get_opt_processes() { get_tmux_option "@stare-processes" "vi vim nvim man less more tial htop btop claude opencode copilot pi"; }

      
M scripts/sessions.sh
···
        27
        27
           local old_last="${dir}/${old}_last"

      
        28
        28
           [[ -L "$old_last" ]] && {

      
        29
        29
             local actual="$(readlink "$old_last")"

      
        30
        
        -    local new_actual="${dir}/${new}_$(basename "$actual" | cut -d_ -f2-)"

      
        
        30
        +    local actual_basename="$(basename "$actual")"

      
        
        31
        +    local timestamp="${actual_basename: -15}"

      
        
        32
        +    local new_actual="${dir}/${new}_${timestamp}"

      
        31
        33
             mv "$actual" "$new_actual"

      
        32
        34
             ln -sf "$new_actual" "${dir}/${new}_last"

      
        33
        35
             rm "$old_last"

      ···
        149
        151
               awk -v command="$command" \

      
        150
        152
                 'BEGIN {FS=OFS="\t"} {$6=command; print}' \

      
        151
        153
                 <<<"$line" >>"$save_file"

      
        152
        
        -    done

      
        
        154
        +      done

      
        153
        155
         }

      
        154
        156
         

      
        155
        157
         link_session_last() {

      ···
        183
        185
         

      
        184
        186
         save_all_sessions() {

      
        185
        187
           tmux list-sessions -F "#{session_name}" | while read -r session; do

      
        186
        
        -    save_session "$session"

      
        187
        
        -  done

      
        
        188
        +  save_session "$session"

      
        
        189
        +done

      
        188
        190
         

      
        189
        
        -  local current_session="$(get_current_session_name)"

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

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

      
        192
        
        -  fi

      
        
        191
        +local current_session="$(get_current_session_name)"

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

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

      
        
        194
        +fi

      
        193
        195
         }

      
        194
        196
         

      
        195
        197
         unload_session() {

      ···
        265
        267
           [[ -n "$session_path" ]] || session_path="$HOME"

      
        266
        268
           tmux new-session -ds "$session_name" -c "$session_path"

      
        267
        269
         

      
        
        270
        +  local initial_window_index

      
        
        271
        +  initial_window_index=$(tmux list-windows -t "$session_name" -F "#{window_index}" | head -1)

      
        
        272
        +  local initial_window_restored=false

      
        
        273
        +

      
        268
        274
           declare -A window_layouts

      
        269
        275
           declare active_window

      
        270
        276
           while read -r line; do

      
        271
        277
             case $line in

      
        272
        
        -    window*)

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

      
        274
        
        -      window_id="$session_name:$window_index"

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

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

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

      
        278
        
        -        active_window="$window_id"

      
        279
        
        -      fi

      
        280
        
        -      ;;

      
        
        278
        +      window*)

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

      
        
        280
        +        window_id="$session_name:$window_index"

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

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

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

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

      
        
        285
        +          active_window="$window_id"

      
        
        286
        +        fi

      
        
        287
        +        ;;

      
        281
        288
         

      
        282
        
        -    pane*)

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

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

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

      
        286
        
        -      else

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

      
        288
        
        -      fi

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

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

      
        291
        
        -      fi

      
        292
        
        -      if should_restore_command "$command"; then

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

      
        294
        
        -      fi

      
        295
        
        -      ;;

      
        
        289
        +      pane*)

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

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

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

      
        
        293
        +        else

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

      
        
        295
        +        fi

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

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

      
        
        298
        +        fi

      
        
        299
        +        if should_restore_command "$command"; then

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

      
        
        301
        +        fi

      
        
        302
        +        ;;

      
        296
        303
             esac

      
        297
        304
           done

      
        
        305
        +

      
        
        306
        +  $initial_window_restored || tmux kill-window -t "$session_name:$initial_window_index" 2>/dev/null || true

      
        298
        307
         

      
        299
        308
           for window in "${!window_layouts[@]}"; do

      
        300
        309
             tmux select-layout -t "$window" "${window_layouts[$window]}"