all repos

tmux-stare @ 4443c84cd1bb7bdfb96953a1b820145f10553e20

session manager, but my session manager

tmux-stare/scripts/helpers.sh (view raw)

Oleksandr Smirnov Oleksandr Smirnov
olexsmir@gmail.com
add list of allowed processes to restore, 1 month ago
1
get_tmux_option() {
2
  local option="$1"
3
  local default_value="$2"
4
  local option_value=$(tmux show-option -gqv "$option")
5
  if [ -z "$option_value" ]; then
6
    echo "$default_value"
7
  else
8
    echo "$option_value"
9
  fi
10
}
11
12
set_tmux_option() {
13
  local option="$1"
14
  local value="$2"
15
  tmux set-option -gq "$option" "$value"
16
}
17
18
get_time() { date +"%Y%m%dT%H%M%S"; }
19
20
# === options
21
get_opt_interval() { get_tmux_option "@stare-interval" "15"; }
22
get_opt_start() { get_tmux_option "@stare-start" ""; }
23
get_opt_last() { get_tmux_option "@stare-last" "0"; }
24
set_opt_last() { set_tmux_option "@stare-last" "$1"; }
25
get_opt_initialized() { get_tmux_option "@stare-initialized" "0"; }
26
set_opt_initialized() { get_tmux_option "@stare-initialized" "$1"; }
27
get_opt_save() { get_tmux_option "@stare-save" "C-s"; }
28
get_opt_pick() { get_tmux_option "@stare-pick" ""; }
29
get_opt_processes() { get_tmux_option "@stare-processes" "vi vim nvim man less more tial htop btop claude opencode copilot pi"; }
30
get_opt_dir() {
31
  local dir="$(get_tmux_option "@stare-dir" "${HOME}/.local/share/tmux/stare" | sed "s,\$HOME,$HOME,g; s,\~,$HOME,g")"
32
  mkdir -p "$dir"
33
  echo "$dir"
34
}
35
36
# === spiner
37
# TODO: use one of those briael fonts
38
new_spinner() {
39
  local current=0
40
  local -r chars="/-\|"
41
  while true; do
42
    tmux display-message -- "${chars:$current:1} $1"
43
    current=$(((current + 1) % 4))
44
    sleep 0.1
45
  done
46
}
47
48
start_spinner() {
49
  new_spinner "$1" &
50
  export SPINNER_PID=$!
51
}
52
53
stop_spinner() {
54
  kill "$SPINNER_PID"
55
  tmux display-message " $1"
56
}