all repos

tmux-stare @ aebb6c842b3137e778758db2b7cbe5f890f1386d

session manager, but my session manager

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

Oleksandr Smirnov Oleksandr Smirnov
olexsmir@gmail.com
fix picker opening on start, 2 days 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_dir() {
37
  local dir="$(get_tmux_option "@stare-dir" "${HOME}/.local/share/tmux/stare" | sed "s,\$HOME,$HOME,g; s,\~,$HOME,g")"
38
  mkdir -p "$dir"
39
  echo "$dir"
40
}
41
42
# === spiner
43
# TODO: use one of those briael fonts
44
new_spinner() {
45
  local current=0
46
  local -r chars="/-\|"
47
  while true; do
48
    tmux display-message -- "${chars:$current:1} $1"
49
    current=$(((current + 1) % 4))
50
    sleep 0.1
51
  done
52
}
53
54
start_spinner() {
55
  new_spinner "$1" &
56
  export SPINNER_PID=$!
57
}
58
59
stop_spinner() {
60
  kill "$SPINNER_PID"
61
  tmux display-message " $1"
62
}