aboutsummaryrefslogtreecommitdiff
path: root/bin/pretty-lock
diff options
context:
space:
mode:
authorAlec Goncharow <alec@goncharow.dev>2025-05-24 12:32:01 -0400
committerAlec Goncharow <alec@goncharow.dev>2025-05-28 16:27:41 -0400
commit42300557bf72c5a267cf89b5902cf58eb1ba6b82 (patch)
treed67736fb7be49853362796109140fe14bbaf64af /bin/pretty-lock
parent9047ba4e1b99410a0454d28b2ca62c12440b9476 (diff)
beep boop
Diffstat (limited to 'bin/pretty-lock')
-rwxr-xr-xbin/pretty-lock27
1 files changed, 27 insertions, 0 deletions
diff --git a/bin/pretty-lock b/bin/pretty-lock
index 8ef40e0..48918f6 100755
--- a/bin/pretty-lock
+++ b/bin/pretty-lock
@@ -1,5 +1,32 @@
#!/bin/sh
+LOCKFILE="$HOME/.local/state/algo/swayidle.lock"
+LOCKDIR="$(dirname "$LOCKFILE")"
+
+# Ensure the directory exists
+mkdir -p "$LOCKDIR"
+
+# Check if lockfile exists and process is running
+if [ -e "$LOCKFILE" ]; then
+ LOCKPID=$(cat "$LOCKFILE")
+ if kill -0 "$LOCKPID" 2>/dev/null; then
+ echo "swayidle is already running with PID $LOCKPID"
+ exit 1
+ else
+ echo "Stale lockfile found. Removing."
+ rm -f "$LOCKFILE"
+ fi
+fi
+
+# Create lockfile with current PID
+echo $$ > "$LOCKFILE"
+
+# Function to clean up on exit
+cleanup() {
+ rm -f "$LOCKFILE"
+}
+trap cleanup EXIT
+
swaylock \
-f \
--screenshots \