mirror of
https://codeberg.org/andyscott/dotfiles.git
synced 2024-12-22 01:43:10 -05:00
Removed gawk extensions, added test for XDG_STATE_HOME env var
This commit is contained in:
parent
37a45f2075
commit
6ee3946a3d
1 changed files with 12 additions and 10 deletions
|
@ -1,22 +1,24 @@
|
|||
#!/bin/sh
|
||||
|
||||
time=$(date +"%b %d, %Y %T")
|
||||
if test -n "$XDG_STATE_HOME"; then
|
||||
log_file=$XDG_STATE_HOME/idle.log
|
||||
|
||||
echo "--- $time ---" > "$log_file"
|
||||
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,7 +28,7 @@ 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" \
|
||||
|
|
Loading…
Reference in a new issue