#!/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