File: ssh-askpass

package info (click to toggle)
git-cola 4.17.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 6,928 kB
  • sloc: python: 38,433; sh: 298; makefile: 223; xml: 110; tcl: 62
file content (83 lines) | stat: -rwxr-xr-x 1,782 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env tclsh
# Tcl ignores the next line -*- tcl -*- \
exec wish "$0" -- "$@"

# This is a trivial implementation of a GIT_ASKPASS / SSH_ASKPASS handler.
# Git-gui uses this script if none are already configured.

package require Tk

set answer {}
set yesno  0
set rc     255

if {$argc < 1} {
	set prompt "Enter your password / passphrase:"
} else {
	set prompt [join $argv " "]
	if {[regexp -nocase {\(yes\/no\)\?\s*$} $prompt]} {
		set yesno 1
	}
}

message .m -text $prompt -justify center -aspect 4000
pack .m -side top -fill x -padx 20 -pady 20 -expand 1

entry .e -textvariable answer -width 50
pack .e -side top -fill x -padx 10 -pady 10

proc on_hide_input_changed {args} {
	global hide_input
	if {$hide_input} {
		.e configure -show "*"
	} else {
		.e configure -show ""
	}
}
trace add variable hide_input write "on_hide_input_changed"

set hide_input 0

if {!$yesno} {
	if {"Password" in $prompt || "passphrase" in $prompt} {
		set hide_input 1
	}

	checkbutton .cb_hide -text "Hide input" -variable hide_input
	pack .cb_hide -side top -anchor nw
}

frame .b
button .b.ok     -text OK     -command finish
button .b.cancel -text Cancel -command cancel

pack .b.ok -side left -expand 1
pack .b.cancel -side right -expand 1
pack .b -side bottom -fill x -padx 10 -pady 10

bind . <Visibility> {focus -force .e}
bind . <Key-Return> [list .b.ok invoke]
bind . <Key-Escape> [list .b.cancel invoke]
bind . <Destroy>    {set rc $rc}

proc cancel {} {
	set ::rc 255
}

proc finish {} {
	if {$::yesno} {
		if {$::answer ne "yes" && $::answer ne "no"} {
			tk_messageBox -icon error -title "Error" -type ok \
				-message "Only 'yes' or 'no' input allowed."
			return
		}
	}

	puts $::answer
	set ::rc 0
}

wm title . "Git Authentication"
tk::PlaceWindow .
vwait rc
exit $rc