From 947364f20f195985fda1d8d363b3e6e9e5ce78ff Mon Sep 17 00:00:00 2001 From: Ryan Date: Thu, 21 Mar 2024 10:41:45 +0800 Subject: [PATCH] format script code --- .config/sway/scripts/logout.sh | 52 +++++++++++++++++----------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/.config/sway/scripts/logout.sh b/.config/sway/scripts/logout.sh index 9fdc9a0..45c0507 100755 --- a/.config/sway/scripts/logout.sh +++ b/.config/sway/scripts/logout.sh @@ -1,41 +1,41 @@ #!/bin/bash # # Modified from sway's locking script +# TODO: remove bashism - -if [[ ! $(which swayidle 2> /dev/null) ]]; then - notify-send "ERROR" "Swayidle not found" - exit 1 +if [[ ! $(which swayidle 2>/dev/null) ]]; then + notify-send "ERROR" "Swayidle not found" + exit 1 fi choices=("suspend" "poweroff" "reboot" "lock") choice=$(printf "%s\n" "${choices[@]}" | fuzzel -d --prompt "🔌: ") +if test "$choice" = lock; then + # sleep less when power on + if acpi -a | grep -q on; then + sleep_time=3600 + else + sleep_time=10 + fi + sleep 0.3 + playerctl stop -if test "$choice" = lock ; then - # sleep less when power on - if acpi -a | grep -q on; then - sleep_time=3600 - else - sleep_time=10 - fi - sleep 0.3 + bright=$(light) - bright=`light` + swayidle -w \ + timeout 5 "light -S 1" resume "light -S $bright" \ + timeout $sleep_time 'swaymsg "output * power off"' resume 'swaymsg "output * power on"' \ + & + idlepid=$! - swayidle -w \ - timeout 5 "light -S 1" resume "light -S $bright" \ - timeout $sleep_time 'swaymsg "output * power off"' resume 'swaymsg "output * power on"' \ - & - idlepid=$! + # swaylock -e -c 282828 --inside-color 00000003 + swaylock -S --effect-blur "12x12" --effect-greyscale --effect-vignette 0.5:0.5 --inside-color 28282860 \ + -e --ring-color 00000000 --line-color 00000000 --indicator --clock --text-color ebdbb2 - # swaylock -e -c 282828 --inside-color 00000003 - swaylock -S --effect-blur "12x12" --effect-greyscale --effect-vignette 0.5:0.5 --inside-color 28282860 \ - -e --ring-color 00000000 --line-color 00000000 --indicator --clock --text-color ebdbb2 - - kill $idlepid - swaymsg "output * power on" - light -S $bright + kill $idlepid + swaymsg "output * power on" + light -S $bright elif test -n "$choice"; then - systemctl $choice + systemctl $choice fi