all repos

tmux-stare @ 6071455

session manager, but my session manager

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

Oleksandr Smirnov Oleksandr Smirnov
olexsmir@gmail.com
shfmt -w -i 2 ., 1 month ago
1
get_time() { date +"%Y%m%dT%H%M%S"; }
2
get_tmux_option() {
3
  local option="$1"
4
  local default_value="$2"
5
  local option_value=$(tmux show-option -gqv "$option")
6
  if [ -z "$option_value" ]; then
7
    echo "$default_value"
8
  else
9
    echo "$option_value"
10
  fi
11
}
12
13
set_tmux_option() {
14
  local option="$1"
15
  local value="$2"
16
  tmux set-option -gq "$option" "$value"
17
}
18
19
wait_for_client() {
20
  local i=0
21
  while [ "$i" -lt 100 ]; do
22
    if tmux list-clients >/dev/null 2>&1; then break; fi
23
    sleep 0.1
24
    i=$((i + 1))
25
  done
26
}
27
28
# === options
29
get_opt_interval() { get_tmux_option "@stare-interval" "15"; }
30
get_opt_start() { get_tmux_option "@stare-start" ""; }
31
get_opt_last() { get_tmux_option "@stare-last" "0"; }
32
set_opt_last() { set_tmux_option "@stare-last" "$1"; }
33
get_opt_save() { get_tmux_option "@stare-save" "C-s"; }
34
get_opt_pick() { get_tmux_option "@stare-pick" ""; }
35
get_opt_processes() { get_tmux_option "@stare-processes" "vi vim nvim man less more tial htop btop claude opencode copilot pi"; }
36
get_opt_ignore() { get_tmux_option "@stare-ignore" "0"; }
37
38
ignored_session() {
39
  local name="$1"
40
  local ignores
41
  IFS=' ' read -ra ignores <<<"$(get_opt_ignore)"
42
  local i
43
  for i in "${ignores[@]}"; do
44
    [[ "$name" == "$i" ]] && return 0
45
  done
46
  return 1
47
}
48
get_opt_dir() {
49
  local dir="$(get_tmux_option "@stare-dir" "${HOME}/.local/share/tmux/stare" | sed "s,\$HOME,$HOME,g; s,\~,$HOME,g")"
50
  mkdir -p "$dir"
51
  echo "$dir"
52
}
53
54
update_session_map() {
55
  local map_file="$(get_opt_dir)/.session_map"
56
  tmux list-sessions -F "#{session_id}\t#{session_name}" 2>/dev/null >"$map_file"
57
}
58
59
# === spinner
60
new_spinner() {
61
  local current=0
62
  local -r chars="⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏"
63
  while true; do
64
    tmux display-message -- "${chars:$current:1} $1"
65
    current=$(((current + 1) % 10))
66
    sleep 0.1
67
  done
68
}
69
70
start_spinner() {
71
  new_spinner "$1" &
72
  export SPINNER_PID=$!
73
}
74
75
stop_spinner() {
76
  kill "$SPINNER_PID"
77
  tmux display-message "  $1"
78
}