#!/bin/sh cmd_exists () { if which "$1" >/dev/null 2>&1; then return 0; else return 1; fi; } fork () { ( "$@" >/dev/null 2>&1 & ) } cmd_running () { if pkill -0 -u "$(id -u)" "$1"; then return 0; else return 1; fi; } should_stop () { if [ "x$1" = "xoff" ] || [ "x$1" = "xstop" ] ; then return 0; else return 1; fi; } if cmd_exists slock && cmd_exists xautolock; then if cmd_running "xautolock"; then if should_stop "$1"; then xautolock -exit; fi; else if ! should_stop "$1"; then fork xautolock -notifier true -bell 0 -locker slock; fi; fi; elif cmd_exists xscreensaver && [ -e ~/.xscreensaver ]; then if cmd_running "xscreensaver"; then if should_stop "$1"; then xscreensaver-command -exit; fi; else if ! should_stop "$1"; then fork XENVIRONMENT=~/.xscreensaver /usr/bin/xscreensaver; fi; fi; elif cmd_exists xautolock; then if cmd_running "xautolock"; then if should_stop "$1"; then xautolock -exit; fi; else if ! should_stop "$1"; then fork xautolock -notifier true -bell 0; fi; fi; fi;