-
Notifications
You must be signed in to change notification settings - Fork 0
/
packet-loss.tmux
executable file
·100 lines (82 loc) · 2.34 KB
/
packet-loss.tmux
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env bash
#
# Copyright (c) 2022-2024: [email protected]
# License: MIT
#
# Part of https://github.com/jaclu/tmux-packet-loss
#
# This is the coordination script
# - ensures the database is present and up to date
# - sets parameters in the database
# - ensures packet_loss_monitor is running
# - binds #{packet_loss} to display_losses.sh
#
#
# Functions only used here are kept here, in order to minimize overhead
# for sourcing utils.sh in the other scripts.
#
do_interpolation() {
local all_interpolated="$1"
all_interpolated=${all_interpolated//$pkt_loss_interpolation/$pkt_loss_command}
echo "$all_interpolated"
}
set_tmux_option() {
local sto_option="$1"
local sto_value="$2"
[[ -z "$sto_option" ]] && {
error_msg "set_tmux_option() param 1 empty!"
}
[[ "$TMUX" = "" ]] && return # this is run standalone
$TMUX_BIN set -g "$sto_option" "$sto_value"
}
update_tmux_option() {
local option="$1"
local option_value
local new_option_value
option_value="$(get_tmux_option "$option")"
new_option_value="$(do_interpolation "$option_value")"
set_tmux_option "$option" "$new_option_value"
}
#===============================================================
#
# Main
#
#===============================================================
D_TPL_BASE_PATH=$(dirname -- "$(realpath "$0")")
log_prefix="plg" # plugin handler
source "$D_TPL_BASE_PATH"/scripts/utils.sh
#
# By printing a NL and date, its easier to keep separate runs apart
#
log_it
log_date_change "plugin handler"
# Ensure a fresh param_cache has been created during plugin init
$param_cache_written || {
generate_param_cache
get_config # to ensure some custom stuff like skip_logging is applied
}
#
# Dependency check
#
command -v sqlite3 >/dev/null 2>&1 || {
error_msg "Missing dependency sqlite3"
}
# Ensure it points to current tmux
get_tmux_pid >"$pidfile_tmux" # helper for show_settings.sh
#
# Start monitor
#
log_it # if log is used, create a LF to better isolate init
log_it "starting monitor"
$scr_ctrl_monitor start
#
# Match tag with polling script
#
pkt_loss_interpolation="\#{packet_loss}"
pkt_loss_command="#($scr_display_losses)"
#
# Activate #{packet_loss} tag if used
#
update_tmux_option "status-left"
update_tmux_option "status-right"
log_it "$current_script - completed"