resources: remove unnecessary os.path.dirname import
[git-cola.git] / cola / bin / ssh-askpass
blob31a1028614225f1b988ead038942d448e9cbea7a
1 #!/usr/bin/env tclsh
2 # Tcl ignores the next line -*- tcl -*- \
3 exec wish "$0" -- "$@"
5 # This is a trivial implementation of a 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 proc on_hide_input_changed {args} {
30         global hide_input
31         if {$hide_input} {
32                 .e configure -show "*"
33         } else {
34                 .e configure -show ""
35         }
37 trace add variable hide_input write "on_hide_input_changed"
39 set hide_input 0
41 if {!$yesno} {
42         if {"Password" in $prompt || "passphrase" in $prompt} {
43                 set hide_input 1
44         }
46         checkbutton .cb_hide -text "Hide input" -variable hide_input
47         pack .cb_hide -side top -anchor nw
50 frame .b
51 button .b.ok     -text OK     -command finish
52 button .b.cancel -text Cancel -command cancel
54 pack .b.ok -side left -expand 1
55 pack .b.cancel -side right -expand 1
56 pack .b -side bottom -fill x -padx 10 -pady 10
58 bind . <Visibility> {focus -force .e}
59 bind . <Key-Return> [list .b.ok invoke]
60 bind . <Key-Escape> [list .b.cancel invoke]
61 bind . <Destroy>    {set rc $rc}
63 proc cancel {} {
64         set ::rc 255
67 proc finish {} {
68         if {$::yesno} {
69                 if {$::answer ne "yes" && $::answer ne "no"} {
70                         tk_messageBox -icon error -title "Error" -type ok \
71                                 -message "Only 'yes' or 'no' input allowed."
72                         return
73                 }
74         }
76         puts $::answer
77         set ::rc 0
80 wm title . "Git Authentication"
81 tk::PlaceWindow .
82 vwait rc
83 exit $rc