-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathhelpers.sh
More file actions
60 lines (49 loc) · 1.57 KB
/
helpers.sh
File metadata and controls
60 lines (49 loc) · 1.57 KB
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
# tmux show-option "q" (quiet) flag does not set return value to 1, even though
# the option does not exist. This function patches that.
get_tmux_option() {
local option=$1
local default_value=$2
local option_value=$(tmux show-option -gqv "$option")
if [ -z "$option_value" ]; then
echo "$default_value"
else
echo "$option_value"
fi
}
# Ensures a message is displayed for 5 seconds in tmux prompt.
# Does not override the 'display-time' tmux option.
display_message() {
local message="$1"
# display_duration defaults to 5 seconds, if not passed as an argument
if [ "$#" -eq 2 ]; then
local display_duration="$2"
else
local display_duration="5000"
fi
# saves user-set 'display-time' option
local saved_display_time=$(get_tmux_option "display-time" "750")
# sets message display time to 5 seconds
tmux set-option -gq display-time "$display_duration"
# displays message
tmux display-message "$message"
# restores original 'display-time' value
tmux set-option -gq display-time "$saved_display_time"
}
tmux_socket() {
echo $TMUX | cut -d',' -f1
}
session_exists_exact() {
tmux has-session -t "=${SESSION_NAME}" >/dev/null 2>&1
}
session_exists_prefix() {
tmux has-session -t "$SESSION_NAME" >/dev/null 2>&1
}
switch_to_session() {
local session_name="$1"
tmux switch-client -t "$session_name"
}
number_of_session_collisions() {
tmux -S "$(tmux_socket)" list-sessions | grep -c "$1"
# this is a temporary implementation, a session might have a similar name or have a name with a higher value than the number of collision
# I need help fixing those potential issues
}