all repos

tmux-stare @ 0a4900f52947b3e0ad9e2c32e4fe488e8ac90ab0

session manager, but my session manager
7 files changed, 43 insertions(+), 28 deletions(-)
auto save
Author: Oleksandr Smirnov olexsmir@gmail.com
Committed at: 2026-02-09 02:08:42 +0200
Authored at: 2026-02-08 22:04:31 +0200
Change ID: zsysrwnqlxvplvrvoozsqlnpzsxzqymn
Parent: d25769b
A scripts/_auto_save.sh
···
        
        1
        +#!/usr/bin/env bash

      
        
        2
        +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

      
        
        3
        +source "$CURRENT_DIR/helpers.sh"

      
        
        4
        +source "$CURRENT_DIR/sessions.sh"

      
        
        5
        +

      
        
        6
        +main() {

      
        
        7
        +  local interval=$(get_opt_interval)

      
        
        8
        +  [[ "$interval" == "0" ]] && exit 0

      
        
        9
        +

      
        
        10
        +  local last=$(get_opt_last)

      
        
        11
        +  local now=$(date +%s)

      
        
        12
        +

      
        
        13
        +  if [[ $((now - last)) -ge $((interval * 60)) ]]; then

      
        
        14
        +    save_all_sessions

      
        
        15
        +    set_opt_last "$now"

      
        
        16
        +  fi

      
        
        17
        +}

      
        
        18
        +main

      
A scripts/_save.sh
···
        
        1
        +#!/usr/bin/env bash

      
        
        2
        +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

      
        
        3
        +source "$CURRENT_DIR/helpers.sh"

      
        
        4
        +source "$CURRENT_DIR/sessions.sh"

      
        
        5
        +

      
        
        6
        +save_all_sessions

      
M scripts/helpers.sh
···
        19
        19
         

      
        20
        20
         # === options

      
        21
        21
         get_opt_interval() { get_tmux_option "@stare-interval" "10"; }

      
        
        22
        +get_opt_last() { get_tmux_option "@stare-last" "0"; }

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

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

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

      
        24
        26
         get_opt_dir() {

      
D scripts/restore.sh
···
        1
        
        -#!/usr/bin/env bash

      
        2
        
        -CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

      
        3
        
        -source "$CURRENT_DIR/helpers.sh"

      
        4
        
        -

      
        5
        
        -# main() {

      
        6
        
        -#   if [[ -n "$1" ]]; then

      
        7
        
        -#     restore_session "$1"

      
        8
        
        -#   else

      
        9
        
        -#     restore_last

      
        10
        
        -#   fi

      
        11
        
        -# }

      
        12
        
        -# main "$@"

      
D scripts/save.sh
···
        1
        
        -#!/usr/bin/env bash

      
        2
        
        -CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

      
        3
        
        -source "$CURRENT_DIR/helpers.sh"

      
        4
        
        -

      
        5
        
        -# TODO: save all sessions

      
        6
        
        -

      
        7
        
        -# # TODO: save all loaded sessions not only current

      
        8
        
        -# main() {

      
        9
        
        -#   local session_name="${1:-$(get_current_session_name)}"

      
        10
        
        -#   start_spinner "Saving session: $session_name"

      
        11
        
        -#   save_session "$session_name"

      
        12
        
        -#   stop_spinner "Session saved"

      
        13
        
        -# }

      
        14
        
        -# main "$@"

      
M scripts/sessions.sh
···
        77
        77
           link_last "$last_file" "$save_dir"

      
        78
        78
         }

      
        79
        79
         

      
        
        80
        +save_all_sessions() {

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

      
        
        82
        +    save_session "$session"

      
        
        83
        +  done

      
        
        84
        +}

      
        
        85
        +

      
        80
        86
         # === restore

      
        81
        87
         restore_session_from_file() {

      
        82
        88
           local session_file="$1"

      
M stare.tmux
···
        4
        4
         CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

      
        5
        5
         source "$CURRENT_DIR/scripts/helpers.sh"

      
        6
        6
         

      
        7
        
        -# TODO: add interval saves (tmux-continuum like)

      
        
        7
        +add_save_interpolation() {

      
        
        8
        +  local status_right_value="$(get_tmux_option "status-right" "")"

      
        
        9
        +  local save_interpolation="#($CURRENT_DIR/scripts/_auto_save.sh)"

      
        
        10
        +

      
        
        11
        +  if [[ "$status_right_value" != *"$save_interpolation"* ]]; then

      
        
        12
        +    set_tmux_option "status-right" "${save_interpolation}${status_right_value}"

      
        
        13
        +  fi

      
        
        14
        +}

      
        8
        15
         

      
        9
        16
         main() {

      
        10
        17
           local pick_key="$(get_opt_pick)"

      ···
        12
        19
             "tmux display-popup -E -w 25% -h 40% '$CURRENT_DIR/scripts/pick.sh'"

      
        13
        20
         

      
        14
        21
           local save_key="$(get_opt_save)"

      
        15
        
        -  [[ -n "$save_key" ]] && tmux bind-key "$save_key" run-shell "$CURRENT_DIR/scripts/save.sh"

      
        
        22
        +  [[ -n "$save_key" ]] && tmux bind-key "$save_key" run-shell "$CURRENT_DIR/scripts/_save.sh"

      
        
        23
        +

      
        
        24
        +  add_save_interpolation

      
        16
        25
         }

      
        17
        26
         main