Alexander Gavrilov | 8c76212 | 2008-10-15 13:28:21 +0400 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # Tcl ignores the next line -*- tcl -*- \ |
| 3 | exec wish "$0" -- "$@" |
| 4 | |
| 5 | # This is a trivial implementation of an SSH_ASKPASS handler. |
| 6 | # Git-gui uses this script if none are already configured. |
| 7 | |
| 8 | set answer {} |
| 9 | set yesno 0 |
| 10 | set rc 255 |
| 11 | |
| 12 | if {$argc < 1} { |
| 13 | set prompt "Enter your OpenSSH passphrase:" |
| 14 | } else { |
| 15 | set prompt [join $argv " "] |
| 16 | if {[regexp -nocase {\(yes\/no\)\?\s*$} $prompt]} { |
| 17 | set yesno 1 |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | message .m -text $prompt -justify center -aspect 4000 |
| 22 | pack .m -side top -fill x -padx 20 -pady 20 -expand 1 |
| 23 | |
| 24 | entry .e -textvariable answer -width 50 |
| 25 | pack .e -side top -fill x -padx 10 -pady 10 |
| 26 | |
| 27 | if {!$yesno} { |
| 28 | .e configure -show "*" |
| 29 | } |
| 30 | |
| 31 | frame .b |
| 32 | button .b.ok -text OK -command finish |
| 33 | button .b.cancel -text Cancel -command {destroy .} |
| 34 | |
| 35 | pack .b.ok -side left -expand 1 |
| 36 | pack .b.cancel -side right -expand 1 |
| 37 | pack .b -side bottom -fill x -padx 10 -pady 10 |
| 38 | |
| 39 | bind . <Visibility> {focus -force .e} |
| 40 | bind . <Key-Return> finish |
| 41 | bind . <Key-Escape> {destroy .} |
| 42 | bind . <Destroy> {exit $rc} |
| 43 | |
| 44 | proc finish {} { |
| 45 | if {$::yesno} { |
| 46 | if {$::answer ne "yes" && $::answer ne "no"} { |
| 47 | tk_messageBox -icon error -title "Error" -type ok \ |
| 48 | -message "Only 'yes' or 'no' input allowed." |
| 49 | return |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | set ::rc 0 |
| 54 | puts $::answer |
| 55 | destroy . |
| 56 | } |
| 57 | |
| 58 | wm title . "OpenSSH" |
| 59 | tk::PlaceWindow . |