]>
Commit | Line | Data |
---|---|---|
8c762125 AG |
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 | ||
aef0b48e PT |
8 | package require Tk |
9 | ||
8c762125 AG |
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 | ||
a4e1bc99 DA |
29 | proc on_show_input_changed {args} { |
30 | global show_input | |
31 | if {$show_input} { | |
32 | .e configure -show "" | |
33 | } else { | |
34 | .e configure -show "*" | |
35 | } | |
36 | } | |
37 | trace add variable show_input write "on_show_input_changed" | |
38 | ||
39 | set show_input 0 | |
40 | ||
8c762125 | 41 | if {!$yesno} { |
a4e1bc99 DA |
42 | checkbutton .cb_show -text "Show input" -variable show_input |
43 | pack .cb_show -side top -anchor nw | |
8c762125 AG |
44 | } |
45 | ||
46 | frame .b | |
47 | button .b.ok -text OK -command finish | |
aef0b48e | 48 | button .b.cancel -text Cancel -command cancel |
8c762125 AG |
49 | |
50 | pack .b.ok -side left -expand 1 | |
51 | pack .b.cancel -side right -expand 1 | |
52 | pack .b -side bottom -fill x -padx 10 -pady 10 | |
53 | ||
54 | bind . <Visibility> {focus -force .e} | |
aef0b48e PT |
55 | bind . <Key-Return> [list .b.ok invoke] |
56 | bind . <Key-Escape> [list .b.cancel invoke] | |
57 | bind . <Destroy> {set rc $rc} | |
58 | ||
59 | proc cancel {} { | |
60 | set ::rc 255 | |
61 | } | |
8c762125 AG |
62 | |
63 | proc finish {} { | |
64 | if {$::yesno} { | |
65 | if {$::answer ne "yes" && $::answer ne "no"} { | |
66 | tk_messageBox -icon error -title "Error" -type ok \ | |
67 | -message "Only 'yes' or 'no' input allowed." | |
68 | return | |
69 | } | |
70 | } | |
71 | ||
850cf9ae LB |
72 | # On Windows, force the encoding to UTF-8: it is what `git.exe` expects |
73 | if {$::tcl_platform(platform) eq {windows}} { | |
74 | set ::answer [encoding convertto utf-8 $::answer] | |
75 | } | |
76 | ||
8c762125 | 77 | puts $::answer |
aef0b48e | 78 | set ::rc 0 |
8c762125 AG |
79 | } |
80 | ||
81 | wm title . "OpenSSH" | |
82 | tk::PlaceWindow . | |
aef0b48e PT |
83 | vwait rc |
84 | exit $rc |