summaryrefslogtreecommitdiff
path: root/polybar/launch.sh
blob: 5b7e0189e1791b9bb3d1f307f017e40fd3703313 (plain)
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
#!/usr/bin/env bash
set -euo pipefail

CONFIG="${XDG_CONFIG_HOME:-$HOME/.config}/polybar/config.ini"
state_dir="${XDG_RUNTIME_DIR:-/tmp}"

if [ ! -w "$state_dir" ]; then
    state_dir="${XDG_CACHE_HOME:-$HOME/.cache}"
    mkdir -p "$state_dir" 2>/dev/null || true
fi

if [ ! -w "$state_dir" ]; then
    state_dir="/tmp"
fi

mode_file="$state_dir/polybar-mode.state"
compact_modules="bar-mode dunst awake pulseaudio keyboard wireguard net-speed network temp cpu memory filesystem tray"
full_modules="bar-mode dunst awake updates screenshot power clipboard display mic pulseaudio music keyboard wireguard net-speed network temp cpu memory filesystem scratchpad tray"

if [ -r "$mode_file" ] && [ "$(cat "$mode_file")" = "full" ]; then
    export POLYBAR_MODULES_RIGHT="$full_modules"
else
    export POLYBAR_MODULES_RIGHT="$compact_modules"
fi

# Kill any running instances before i3 reloads the bar.
killall -q polybar || true
while pgrep -u "$UID" -x polybar >/dev/null; do
    sleep 0.1
done

mapfile -t monitors < <(polybar --list-monitors 2>/dev/null | cut -d: -f1 || true)

if [ "${#monitors[@]}" -eq 0 ]; then
    polybar --reload main -c "$CONFIG" &
    exit 0
fi

for monitor in "${monitors[@]}"; do
    MONITOR="$monitor" polybar --reload main -c "$CONFIG" &
done