-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolybar.sh
executable file
·91 lines (78 loc) · 1.84 KB
/
polybar.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
#!/bin/sh
# path: /home/klassiker/.local/share/repos/polybar/polybar.sh
# author: klassiker [mrdotx]
# github: https://github.com/mrdotx/polybar
# date: 2024-08-17T18:56:08+0200
service="polybar.service"
script=$(basename "$0")
help="$script [-h/--help] -- script to start polybar
Usage:
$script [--kill/--reload/--restart/--toggle]
Settings:
without given settings, re-/start polybar
[--kill] = terminate already running polybar instances
[--reload] = reload polybar modules
[--restart] = restart polybar
[--toggle] = toggle polybar visibility
Example:
$script
$script --kill
$script --reload
$script --restart"
get_monitor() {
polybar -m \
| sed -n "${1}p" \
| cut -d ':' -f1
}
quit_bar() {
polybar-msg cmd quit >/dev/null 2>&1
}
get_value() {
case $1 in
top) printf "false";;
bottom) printf "true";;
pinned) printf "true";;
unpinned) printf "false";;
esac
}
exec_bar() {
MONITOR="$1" \
BOTTOM="$(get_value "$2")" \
I3PIN="$(get_value "$3")" \
polybar "$4" &
}
start() {
quit_bar
primary=$(get_monitor 1)
secondary=$(get_monitor 2)
# type = blank, sys_info_s, sys_info, main_s, main
case "$secondary" in
"")
exec_bar "$primary" "top" "unpinned" "main_s"
;;
*)
exec_bar "$primary" "top" "pinned" "main"
exec_bar "$secondary" "top" "pinned" "sys_info"
;;
esac
}
case "$1" in
-h | --help)
printf "%s\n" "$help"
;;
--kill)
quit_bar
;;
--restart)
systemctl --user restart "$service"
;;
--reload)
polybar-msg cmd restart >/dev/null 2>&1
;;
--toggle)
polybar-msg cmd toggle >/dev/null 2>&1
;;
*)
start
;;
esac