summaryrefslogtreecommitdiff
path: root/polybar/launch.sh
diff options
context:
space:
mode:
authorDavid Moc <personal@cdatgoose.org>2026-05-24 11:48:07 +0200
committerDavid Moc <personal@cdatgoose.org>2026-05-24 11:48:07 +0200
commit5fb19f10389b70ee2389755106092a9ef6c64598 (patch)
tree969eb0466de581cb14aa09f751a95138620fc720 /polybar/launch.sh
Go
Diffstat (limited to 'polybar/launch.sh')
-rwxr-xr-xpolybar/launch.sh41
1 files changed, 41 insertions, 0 deletions
diff --git a/polybar/launch.sh b/polybar/launch.sh
new file mode 100755
index 0000000..5b7e018
--- /dev/null
+++ b/polybar/launch.sh
@@ -0,0 +1,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