summaryrefslogtreecommitdiff
path: root/polybar/scripts/bar-mode-toggle.sh
blob: d943df16546e87129ba0714dae8f5616b9406593 (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
42
43
44
45
46
47
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 &