lock: fixed locking on Macs and cleaned up the code.

This commit is contained in:
Adrian Kreher 2009-02-25 12:29:55 -06:00
parent 624080c735
commit 47e3200daa

19
lock
View file

@ -2,14 +2,21 @@
# Yell if they are trying to lock remotely. This won't work.
# Even if it does, it's wrong.
if [ "${SSH_TTY}" ] ; then
if [ "${SSH_TTY}" ] && [ -z "${STY}" ] ; then
echo "You're doing it wrong. Don't try to lock a remote computer."
exit 1
fi
# Graphically locking on Macs is simple.
# If we're not in screen, attempt to graphically lock it.
if [ `uname -s` = 'Darwin' ] && [ -z "${STY}" ] ; then
/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend
exit
fi
# Handle non-graphical locking
if [ -z $DISPLAY ] ; then
if [ -z $STY ] ; then # not running screen
if [ -z "${DISPLAY}" ] ; then
if [ -z "${STY}" ] ; then # not running screen
if ( command -v vlock >/dev/null 2>/dev/null ) ; then
vlock
exit
@ -22,12 +29,6 @@ if [ -z $DISPLAY ] ; then
exit 1
fi
# Locking on Macs is simple.
if [ `uname -s` = 'Darwin' ] ; then
/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend
exit
fi
# Try to lock sanely on X11.
# Certain combinations of desktop managers and locking programs
# allow new sessions to be started.