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 | |
Pat Thoyts | aef0b48 | 2010-08-18 23:19:24 +0100 | [diff] [blame] | 8 | package require Tk |
| 9 | |
Alexander Gavrilov | 8c76212 | 2008-10-15 13:28:21 +0400 | [diff] [blame] | 10 | set answer {} |
| 11 | set yesno 0 |
| 12 | set rc 255 |
| 13 | |
| 14 | if {$argc < 1} { |
| 15 | set prompt "Enter your OpenSSH passphrase:" |
| 16 | } else { |
| 17 | set prompt [join $argv " "] |
| 18 | if {[regexp -nocase {\(yes\/no\)\?\s*$} $prompt]} { |
| 19 | set yesno 1 |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | message .m -text $prompt -justify center -aspect 4000 |
| 24 | pack .m -side top -fill x -padx 20 -pady 20 -expand 1 |
| 25 | |
| 26 | entry .e -textvariable answer -width 50 |
| 27 | pack .e -side top -fill x -padx 10 -pady 10 |
| 28 | |
| 29 | if {!$yesno} { |
| 30 | .e configure -show "*" |
| 31 | } |
| 32 | |
| 33 | frame .b |
| 34 | button .b.ok -text OK -command finish |
Pat Thoyts | aef0b48 | 2010-08-18 23:19:24 +0100 | [diff] [blame] | 35 | button .b.cancel -text Cancel -command cancel |
Alexander Gavrilov | 8c76212 | 2008-10-15 13:28:21 +0400 | [diff] [blame] | 36 | |
| 37 | pack .b.ok -side left -expand 1 |
| 38 | pack .b.cancel -side right -expand 1 |
| 39 | pack .b -side bottom -fill x -padx 10 -pady 10 |
| 40 | |
| 41 | bind . <Visibility> {focus -force .e} |
Pat Thoyts | aef0b48 | 2010-08-18 23:19:24 +0100 | [diff] [blame] | 42 | bind . <Key-Return> [list .b.ok invoke] |
| 43 | bind . <Key-Escape> [list .b.cancel invoke] |
| 44 | bind . <Destroy> {set rc $rc} |
| 45 | |
| 46 | proc cancel {} { |
| 47 | set ::rc 255 |
| 48 | } |
Alexander Gavrilov | 8c76212 | 2008-10-15 13:28:21 +0400 | [diff] [blame] | 49 | |
| 50 | proc finish {} { |
| 51 | if {$::yesno} { |
| 52 | if {$::answer ne "yes" && $::answer ne "no"} { |
| 53 | tk_messageBox -icon error -title "Error" -type ok \ |
| 54 | -message "Only 'yes' or 'no' input allowed." |
| 55 | return |
| 56 | } |
| 57 | } |
| 58 | |
Luke Bonanomi | 850cf9a | 2020-03-12 21:31:50 +0000 | [diff] [blame] | 59 | # On Windows, force the encoding to UTF-8: it is what `git.exe` expects |
| 60 | if {$::tcl_platform(platform) eq {windows}} { |
| 61 | set ::answer [encoding convertto utf-8 $::answer] |
| 62 | } |
| 63 | |
Alexander Gavrilov | 8c76212 | 2008-10-15 13:28:21 +0400 | [diff] [blame] | 64 | puts $::answer |
Pat Thoyts | aef0b48 | 2010-08-18 23:19:24 +0100 | [diff] [blame] | 65 | set ::rc 0 |
Alexander Gavrilov | 8c76212 | 2008-10-15 13:28:21 +0400 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | wm title . "OpenSSH" |
| 69 | tk::PlaceWindow . |
Pat Thoyts | aef0b48 | 2010-08-18 23:19:24 +0100 | [diff] [blame] | 70 | vwait rc |
| 71 | exit $rc |