7 files changed,
43 insertions(+),
28 deletions(-)
Author:
Oleksandr Smirnov
olexsmir@gmail.com
Committed at:
2026-02-09 02:08:42 +0200
Change ID:
zsysrwnqlxvplvrvoozsqlnpzsxzqymn
Parent:
d25769b
A
scripts/_auto_save.sh
@@ -0,0 +1,18 @@
+#!/usr/bin/env bash +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "$CURRENT_DIR/helpers.sh" +source "$CURRENT_DIR/sessions.sh" + +main() { + local interval=$(get_opt_interval) + [[ "$interval" == "0" ]] && exit 0 + + local last=$(get_opt_last) + local now=$(date +%s) + + if [[ $((now - last)) -ge $((interval * 60)) ]]; then + save_all_sessions + set_opt_last "$now" + fi +} +main
A
scripts/_save.sh
@@ -0,0 +1,6 @@
+#!/usr/bin/env bash +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "$CURRENT_DIR/helpers.sh" +source "$CURRENT_DIR/sessions.sh" + +save_all_sessions
M
scripts/helpers.sh
@@ -19,6 +19,8 @@ get_time() { date +"%Y%m%dT%H%M%S"; }
# === options get_opt_interval() { get_tmux_option "@stare-interval" "10"; } +get_opt_last() { get_tmux_option "@stare-last" "0"; } +set_opt_last() { set_tmux_option "@stare-last" "$1"; } get_opt_save() { get_tmux_option "@stare-save" "C-s"; } get_opt_pick() { get_tmux_option "@stare-pick" ""; } get_opt_dir() {
D
@@ -1,14 +0,0 @@
-#!/usr/bin/env bash -CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -source "$CURRENT_DIR/helpers.sh" - -# TODO: save all sessions - -# # TODO: save all loaded sessions not only current -# main() { -# local session_name="${1:-$(get_current_session_name)}" -# start_spinner "Saving session: $session_name" -# save_session "$session_name" -# stop_spinner "Session saved" -# } -# main "$@"
M
scripts/sessions.sh
@@ -77,6 +77,12 @@ link_session_last "$save_file" "$last_file"
link_last "$last_file" "$save_dir" } +save_all_sessions() { + tmux list-sessions -F "#{session_name}" | while read -r session; do + save_session "$session" + done +} + # === restore restore_session_from_file() { local session_file="$1"
M
stare.tmux
@@ -4,7 +4,14 @@
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "$CURRENT_DIR/scripts/helpers.sh" -# TODO: add interval saves (tmux-continuum like) +add_save_interpolation() { + local status_right_value="$(get_tmux_option "status-right" "")" + local save_interpolation="#($CURRENT_DIR/scripts/_auto_save.sh)" + + if [[ "$status_right_value" != *"$save_interpolation"* ]]; then + set_tmux_option "status-right" "${save_interpolation}${status_right_value}" + fi +} main() { local pick_key="$(get_opt_pick)"@@ -12,6 +19,8 @@ [[ -n "$pick_key" ]] && tmux bind-key "$pick_key" run-shell \
"tmux display-popup -E -w 25% -h 40% '$CURRENT_DIR/scripts/pick.sh'" local save_key="$(get_opt_save)" - [[ -n "$save_key" ]] && tmux bind-key "$save_key" run-shell "$CURRENT_DIR/scripts/save.sh" + [[ -n "$save_key" ]] && tmux bind-key "$save_key" run-shell "$CURRENT_DIR/scripts/_save.sh" + + add_save_interpolation } main