#! /bin/sh

#
# An SSH_ASKPASS command for MacOS X
#
# Original script from:
#   http://blog.retep.org/2009/04/09/ssh-askpass-on-osx-10-5/
#   Author: Joseph Mocker, Sun Microsystems
#

#
# To use this script:
#     setenv SSH_ASKPASS "macos-askpass"
#     setenv DISPLAY ":0"
#

TITLE=${MACOS_ASKPASS_TITLE:-"SSH"}

DIALOG="display dialog \"$@\" default answer \"\" with title \"$TITLE\""
DIALOG="$DIALOG with icon caution with hidden answer"

result=`osascript -e 'tell application "MacVim"' -e "activate"  -e "$DIALOG" -e "text returned of result" -e 'end tell'`

if [ "$result" = "" ]; then
    exit 1
else
    echo "$result"
    exit 0
fi
