diff --git a/lock b/lock index ce2ca33..ac5a571 100755 --- a/lock +++ b/lock @@ -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.