Removed gawk extensions, added test for XDG_STATE_HOME env var

This commit is contained in:
Andrew Scott 2024-02-25 11:06:26 -05:00
parent 37a45f2075
commit 6ee3946a3d
Signed by: a
GPG key ID: 7CD5A5977E4931C1

View file

@ -1,22 +1,24 @@
#!/bin/sh
time=$(date +"%b %d, %Y %T")
log_file=$XDG_STATE_HOME/idle.log
echo "--- $time ---" > "$log_file"
if test -n "$XDG_STATE_HOME"; then
log_file=$XDG_STATE_HOME/idle.log
else
log_file=$HOME/.local/state/idle.log
fi
echo "--- $(date +"%Y-%m-%d %T") ---" > "$log_file"
# kill process if already running
user=$(id -u)
pid=$(ps -u "$user" | awk '/\<swayidle\>/ {print $1}')
pid=$(ps -o pid,comm -u "$user" | awk '$2=="swayidle" {print $1}')
if [ "$pid" != "" ]; then
echo "Sending SIGTERM to swayidle." >> "$log_file"
echo "Restarting... Sending SIGTERM." >> "$log_file"
kill "$pid"
sleep 1
fi
pid=$(ps -u "$user" | awk '/\<swayidle\>/ {print $1}')
pid=$(ps -o pid,comm -p "$pid" | awk '$2=="swayidle" {print $1}')
if [ "$pid" != "" ]; then
echo "Sending SIGKILL to swayidle." >> "$log_file"
echo "Restarting... Sending SIGKILL." >> "$log_file"
kill -9 "$pid"
sleep 1
fi
@ -26,12 +28,12 @@ fi
brightness="/sys/class/backlight/amdgpu_bl1/brightness"
prev_brightness="${XDG_STATE_HOME}/prev_brightness"
swayidle -w \
timeout 120 "cat $brightness > $prev_brightness && echo 1 > $brightness" \
timeout 120 "cat $brightness > $prev_brightness && echo 0 > $brightness" \
resume "cat $prev_brightness > $brightness" \
timeout 300 'waylock-launcher' \
resume "cat $prev_brightness > $brightness" \
timeout 900 "cat $prev_brightness > $brightness && wlr-randr --output eDP-1 --off" \
resume "wlr-randr --output eDP-1 --on && kanshictl reload" \
resume "wlr-randr --output eDP-1 --on && kanshictl reload" \
timeout 3600 "loginctl suspend-then-hibernate" \
resume "wlr-randr --output eDP-1 --on && kanshictl reload" \
lock "waylock-launcher" \