summaryrefslogtreecommitdiff
path: root/polybar/scripts/bar-mode-toggle.sh
diff options
context:
space:
mode:
Diffstat (limited to 'polybar/scripts/bar-mode-toggle.sh')
-rwxr-xr-xpolybar/scripts/bar-mode-toggle.sh48
1 files changed, 48 insertions, 0 deletions
diff --git a/polybar/scripts/bar-mode-toggle.sh b/polybar/scripts/bar-mode-toggle.sh
new file mode 100755
index 0000000..d943df1
--- /dev/null
+++ b/polybar/scripts/bar-mode-toggle.sh
@@ -0,0 +1,48 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+requested="${1:-toggle}"
+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"
+
+current="compact"
+if [ -r "$mode_file" ]; then
+ current="$(cat "$mode_file")"
+fi
+
+case "$requested" in
+ full|expand|expanded)
+ next="full"
+ ;;
+ compact|minimize|minimized)
+ next="compact"
+ ;;
+ toggle)
+ if [ "$current" = "full" ]; then
+ next="compact"
+ else
+ next="full"
+ fi
+ ;;
+ *)
+ exit 2
+ ;;
+esac
+
+printf '%s\n' "$next" >"$mode_file"
+
+if command -v dunstify >/dev/null 2>&1; then
+ dunstify -a polybar -u low "Polybar" "$next mode"
+fi
+
+/home/aag/.config/polybar/launch.sh >/tmp/polybar-mode-toggle.log 2>&1 &