all repos

tmux-stare @ 08c0b8cbf62f4585cd88d37aefa7d857ef26e4b8

session manager, but my session manager

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

Oleksandr Smirnov Oleksandr Smirnov
olexsmir@gmail.com
keep text alighted when spinner is stopped, 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_dir() {
30
  local dir="$(get_tmux_option "@stare-dir" "${HOME}/.local/share/tmux/stare" | sed "s,\$HOME,$HOME,g; s,\~,$HOME,g")"
31
  mkdir -p "$dir"
32
  echo "$dir"
33
}
34
35
# === spiner
36
# TODO: use one of those briael fonts
37
new_spinner() {
38
  local current=0
39
  local -r chars="/-\|"
40
  while true; do
41
    tmux display-message -- "${chars:$current:1} $1"
42
    current=$(((current + 1) % 4))
43
    sleep 0.1
44
  done
45
}
46
47
start_spinner() {
48
  new_spinner "$1" &
49
  export SPINNER_PID=$!
50
}
51
52
stop_spinner() {
53
  kill "$SPINNER_PID"
54
  tmux display-message " $1"
55
}