summaryrefslogtreecommitdiff
path: root/.config/eww/scripts/toggle
diff options
context:
space:
mode:
Diffstat (limited to '.config/eww/scripts/toggle')
-rwxr-xr-x.config/eww/scripts/toggle17
1 files changed, 17 insertions, 0 deletions
diff --git a/.config/eww/scripts/toggle b/.config/eww/scripts/toggle
new file mode 100755
index 0000000..8ce7bcc
--- /dev/null
+++ b/.config/eww/scripts/toggle
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+set -e
+
+# Open a file descriptor for writing to create the lock if it doesn’t exist. We
+# need a lock because of race-conditions that could occur if you spam a toggle
+# over and over.
+exec 3>"${XDG_RUNTIME_DIR:-/run/user/`id -u`}/eww-toggle.lock"
+flock 3
+
+for arg in "$@"; do
+ {
+ eww windows | grep -q "^\\*$arg$" && f=close || f=open
+ eww $f "$arg"
+ } &
+done
+wait