-
Notifications
You must be signed in to change notification settings - Fork 0
/
i3_helper.sh
executable file
·104 lines (89 loc) · 2.78 KB
/
i3_helper.sh
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
101
102
103
104
#!/bin/sh
# path: /home/klassiker/.local/share/repos/i3/i3_helper.sh
# author: klassiker [mrdotx]
# github: https://github.com/mrdotx/i3
# date: 2024-06-02T07:34:58+0200
i3_set_spacer() {
i3_set_spacer_i=$1
while [ "$i3_set_spacer_i" -gt 0 ]; do
printf "%s" "${2:-" "}"
i3_set_spacer_i=$((i3_set_spacer_i - 1))
done
}
i3_table() {
i3_table_line="─"
i3_table_line_divider="┬"
i3_table_row_divider="│"
i3_table_fixed_column=3
i3_table_variable_column=$(($1 - 2 - (2 * i3_table_fixed_column)))
case "$2" in
header)
printf "<i>%s</i>\n%s%s%s%s%s" \
"$3" \
"$(i3_set_spacer "$i3_table_variable_column" "$i3_table_line")" \
"$i3_table_line_divider" \
"$(i3_set_spacer "$i3_table_fixed_column" "$i3_table_line")" \
"$i3_table_line_divider" \
"$(i3_set_spacer "$i3_table_fixed_column" "$i3_table_line")"
;;
*)
printf " %s %s%s %s %s <b>%s</b>" \
"$4" \
"$(i3_set_spacer "$((i3_table_variable_column - ${#4} - 2))")" \
"$i3_table_row_divider" \
"$3" \
"$i3_table_row_divider" \
"$2"
;;
esac
}
i3_notify() {
# WORKAROUND: notifications are sometimes not closed
sleep .1
i3_notify_timer="$1"
i3_notify_title="$2 [i3 mode]"
i3_notify_message="$3"
case "$i3_notify_message" in
"mouse pointer moved"*)
i3_notification_urgency="low"
;;
*)
i3_notification_urgency="normal"
;;
esac
notify-send \
-t "$i3_notify_timer" \
-u "$i3_notification_urgency" \
"$i3_notify_title" \
"$i3_notify_message" \
-h string:x-canonical-private-synchronous:"$i3_notify_title"
}
i3_notify_progress() {
# WORKAROUND: notifications are sometimes not closed
sleep .1
i3_notify_progress_timer="$1"
i3_notify_progress_title="$2 [i3 mode]"
i3_notify_progress_message="$3"
i3_notify_progress_value="$4"
notify-send \
-t "$i3_notify_progress_timer" \
-u "low" \
"$i3_notify_progress_title" \
"$i3_notify_progress_message" \
-h string:x-canonical-private-synchronous:"$i3_notify_progress_title" \
-h int:value:"$i3_notify_progress_value"
}
i3_net_check() {
i3_net_check_address=${1:-1.1.1.1}
i3_net_check_interval=${2:-10}
while ! ping -c1 -W1 -q "$i3_net_check_address" >/dev/null 2>&1 \
&& [ "$i3_net_check_interval" -gt 0 ]; do
sleep .1
i3_net_check_interval=$((i3_net_check_interval - 1))
done
case "$i3_net_check_interval" in
0)
exit 1
;;
esac
}