blob: 1c99ee8ca20d43f45bb733ca1f9516aa6c9c9e97 [file] [log] [blame]
Alexander Gavrilov8c762122008-10-15 13:28:21 +04001#!/bin/sh
2# Tcl ignores the next line -*- tcl -*- \
3exec 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 Thoytsaef0b482010-08-18 23:19:24 +01008package require Tk
9
Alexander Gavrilov8c762122008-10-15 13:28:21 +040010set answer {}
11set yesno 0
12set rc 255
13
14if {$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
23message .m -text $prompt -justify center -aspect 4000
24pack .m -side top -fill x -padx 20 -pady 20 -expand 1
25
26entry .e -textvariable answer -width 50
27pack .e -side top -fill x -padx 10 -pady 10
28
29if {!$yesno} {
30 .e configure -show "*"
31}
32
33frame .b
34button .b.ok -text OK -command finish
Pat Thoytsaef0b482010-08-18 23:19:24 +010035button .b.cancel -text Cancel -command cancel
Alexander Gavrilov8c762122008-10-15 13:28:21 +040036
37pack .b.ok -side left -expand 1
38pack .b.cancel -side right -expand 1
39pack .b -side bottom -fill x -padx 10 -pady 10
40
41bind . <Visibility> {focus -force .e}
Pat Thoytsaef0b482010-08-18 23:19:24 +010042bind . <Key-Return> [list .b.ok invoke]
43bind . <Key-Escape> [list .b.cancel invoke]
44bind . <Destroy> {set rc $rc}
45
46proc cancel {} {
47 set ::rc 255
48}
Alexander Gavrilov8c762122008-10-15 13:28:21 +040049
50proc 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 Bonanomi850cf9a2020-03-12 21:31:50 +000059 # 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 Gavrilov8c762122008-10-15 13:28:21 +040064 puts $::answer
Pat Thoytsaef0b482010-08-18 23:19:24 +010065 set ::rc 0
Alexander Gavrilov8c762122008-10-15 13:28:21 +040066}
67
68wm title . "OpenSSH"
69tk::PlaceWindow .
Pat Thoytsaef0b482010-08-18 23:19:24 +010070vwait rc
71exit $rc