-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpolybar-sxhkd.sh
executable file
·77 lines (63 loc) · 2.03 KB
/
polybar-sxhkd.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
#!/usr/bin/env bash
# ============================================================================
# Configuration Section
# ============================================================================
declare -r ADDRESS="/run/user/$UID/sxhkd.fifo.sxhkd-statusd"
declare -r LABEL_PREFIX=" "
declare -r LABEL_SUFFIX=" "
# List of the labels ---------------------------------------------------------
#
# Key: 'H' + the prefix of hotkey chain to disply including ALL WHITESPACES.
# all whitespaces are not trimmed, including the last one.
#
# Value: Label of the hotkey chain to display
#
# ----------------------------------------------------------------------------
declare -Ar LABEL_TABLE=(
["Hsuper + r"]="Resize Windows" # Example for single prefix
)
# ============================================================================
# Script Section
# ============================================================================
declare -i REGISTER_CHAINMODE=1
remove_label () {
echo ""
}
display_label () {
echo "$LABEL_PREFIX$1$LABEL_SUFFIX"
}
# If input is hotkey, find label in the list and display the label
event_hotkey () {
local -r event="$1"
local key
local val
for key in "${!LABEL_TABLE[@]}"; do
val="${LABEL_TABLE[$key]}"
[[ $(echo "$event" | grep "$key$") ]] && display_label "$val"
done
}
# If chain is begin, turn the REGISTER_CHAINMODE on
event_begin () {
REGISTER_CHAINMODE=0
}
# If chain is aborted, turn the register off and remove the label
event_end () {
remove_label
REGISTER_CHAINMODE=1
}
# Check input event
handle_event () {
local -r event="$1"
[[ $(echo "$event" | grep "^H") ]] && event_hotkey "$event"
[[ $(echo "$event" | grep "^BBegin") ]] && event_begin
[[ $(echo "$event" | grep "^EEnd") ]] && event_end
[[ $(echo "$event" | grep "^C") ]] && [[ ! $REGISTER_CHAINMODE ]] && event_end
}
# Waiting input event from pipe
loop () {
(socat UNIX-CONNECT:$ADDRESS -) | \
while read event; do
handle_event "$event"
done
}
loop