#!/bin/bash
# SSH_ASKPASS helper for Commander.app
# SSH invokes this when it needs a password/passphrase and has no TTY.
# Shows a native macOS dialog via osascript and returns the input on stdout.

PROMPT="${1:-SSH password required}"

# Use osascript to show a secure input dialog
RESULT=$(osascript -e "
    set dialogResult to display dialog \"$PROMPT\" with title \"SSH password required\" default answer \"\" with hidden answer buttons {\"Cancel\", \"Connect\"} default button \"Connect\"
    return text returned of dialogResult
" 2>/dev/null)

EXIT=$?
if [ $EXIT -ne 0 ]; then
    exit 1
fi

echo "$RESULT"
