sway: structure scripts, add helpers in separate file

This commit is contained in:
Konstantin Koslowski 2021-01-04 18:27:42 +01:00
parent 307d1dd03d
commit 9a4b96932a
5 changed files with 86 additions and 70 deletions

View file

@ -1,50 +1,18 @@
#!/bin/bash
source $HOME/.config/sway/bin/helpers
IMAGE=$HOME/.lockscreen.jpg
SCROT_APP=grim
SCROT_ARGS=" -t jpeg"
LOCK_APP=swaylock
LOCK_ARGS=" -f -c 000000 -i $IMAGE"
INHIBIT_FILE=$HOME/.inhibit
function _check_app() {
which $1 &> /dev/null
if [ $? -ne 0 ]; then
echo "ERROR: missing app \"$1\""
exit 1
fi
}
function _check_inhibit() {
if [ -e $INHIBIT_FILE ]; then
echo "ERROR: found inhibit file $INHIBIT_FILE"
exit 1
fi
}
function _inhibit() {
case "$1" in
0|off)
rm -f $INHIBIT_FILE
echo "inhibit disabled"
;;
1|on)
touch $INHIBIT_FILE
echo "inhibit enabled"
;;
*)
echo "ERROR: unknown argument: $1"
;;
esac
}
INHIBIT_FILE=$HOME/.inhibit_lock
function _clean() {
rm -vf $IMAGE
}
function _lock() {
_check_inhibit
_check_app $LOCK_APP
_check_inhibit $INHIBIT_FILE
$LOCK_APP $LOCK_ARGS
}
@ -57,22 +25,18 @@ function _on() {
}
function _screenshot() {
_check_app $SCROT_APP
$SCROT_APP $SCROT_ARGS $IMAGE
convert -blur 4x4 $IMAGE $IMAGE
}
function _suspend() {
_check_inhibit
systemctl suspend-then-hibernate
}
mkdir -p $HOME/log
echo "lock: $(date) args: $*" >> $HOME/log/sway.log
## main
_log LOCK INFO args: $*
_check_app $LOCK_APP
_check_app $SCROT_APP
case "$1" in
inhibit)
_inhibit $2
_set_inhibit $INHIBIT_FILE $2
;;
lock)
_on
@ -96,12 +60,9 @@ case "$1" in
_on
_screenshot
;;
suspend)
_suspend
;;
*)
echo "invalid argument \"$1\"."
echo "arguments: [lock|lockonly|off|on|screenshot]"
echo "invalid argument \"$1\""
echo "arguments: [inhibit [on|off]|lock|lockonly|off|on|screenshot]"
esac