ssh-askpass: also hide passphrase
[git-cola.git] / share / git-cola / bin / ssh-askpass
blob0b1bf88e33475306349ae5cfdcbbbad2c7fb1f11
1 #!/usr/bin/env tclsh
2 # Tcl ignores the next line -*- tcl -*- \
3 exec wish "$0" -- "$@"
5 # This is a trivial implementation of an GIT_ASKPASS / SSH_ASKPASS handler.
6 # Git-gui uses this script if none are already configured.
8 package require Tk
10 set answer {}
11 set yesno  0
12 set rc     255
14 if {$argc < 1} {
15         set prompt "Enter your password / passphrase:"
16 } else {
17         set prompt [join $argv " "]
18         if {[regexp -nocase {\(yes\/no\)\?\s*$} $prompt]} {
19                 set yesno 1
20         }
23 message .m -text $prompt -justify center -aspect 4000
24 pack .m -side top -fill x -padx 20 -pady 20 -expand 1
26 entry .e -textvariable answer -width 50
27 pack .e -side top -fill x -padx 10 -pady 10
29 if {!$yesno} {
30         if {"Password" in $prompt || "passphrase" in $prompt} {
31                 .e configure -show "*"
32         }
35 frame .b
36 button .b.ok     -text OK     -command finish
37 button .b.cancel -text Cancel -command cancel
39 pack .b.ok -side left -expand 1
40 pack .b.cancel -side right -expand 1
41 pack .b -side bottom -fill x -padx 10 -pady 10
43 bind . <Visibility> {focus -force .e}
44 bind . <Key-Return> [list .b.ok invoke]
45 bind . <Key-Escape> [list .b.cancel invoke]
46 bind . <Destroy>    {set rc $rc}
48 proc cancel {} {
49         set ::rc 255
52 proc finish {} {
53         if {$::yesno} {
54                 if {$::answer ne "yes" && $::answer ne "no"} {
55                         tk_messageBox -icon error -title "Error" -type ok \
56                                 -message "Only 'yes' or 'no' input allowed."
57                         return
58                 }
59         }
61         puts $::answer
62         set ::rc 0
65 wm title . "Git Authentication"
66 tk::PlaceWindow .
67 vwait rc
68 exit $rc