1 # git-gui about git-gui dialog
2 # Copyright (C) 2006, 2007 Shawn Pearce
5 foreach name
{~
/.ssh
/id_dsa.pub ~
/.ssh
/id_rsa.pub ~
/.ssh
/identity.pub
} {
6 if {[file exists
$name]} {
10 return [list $name $cont]
18 global sshkey_title have_tk85 sshkey_fd use_ttk NS
21 if {[winfo exists
$w]} {
29 set finfo
[find_ssh_key
]
31 set sshkey_title
[mc
"No keys found."]
34 set sshkey_title
[mc
"Found a public key in: %s" [lindex $finfo 0]]
35 set gen_state disabled
38 ${NS
}::frame $w.header
39 ${NS
}::label $w.header.lbl
-textvariable sshkey_title
-anchor w
40 ${NS
}::button $w.header.gen
-text [mc
"Generate Key"] \
41 -command [list make_ssh_key
$w] -state $gen_state
42 pack $w.header.lbl
-side left
-expand 1 -fill x
43 pack $w.header.gen
-side right
44 pack $w.header
-fill x
-pady 5 -padx 5
46 text $w.contents
-width 60 -height 10 -wrap char
-relief sunken
47 pack $w.contents
-fill both
-expand 1
50 if {$use_ttk} { set clr
[ttk
::style lookup .
-selectbackground] }
51 $w.contents configure
-inactiveselectbackground $clr
54 ${NS
}::frame $w.buttons
55 ${NS
}::button $w.buttons.
close -text [mc Close
] \
56 -default active
-command [list destroy $w]
57 pack $w.buttons.
close -side right
58 ${NS
}::button $w.buttons.copy
-text [mc
"Copy To Clipboard"] \
59 -command [list tk_textCopy $w.contents
]
60 pack $w.buttons.copy
-side left
61 pack $w.buttons
-side bottom
-fill x
-pady 5 -padx 5
64 $w.contents insert end
[lindex $finfo 1] sel
66 $w.contents configure
-state disabled
68 bind $w <Visibility
> "grab $w; focus $w.buttons.close"
69 bind $w <Key-Escape
> "destroy $w"
70 bind $w <Key-Return
> "destroy $w"
71 bind $w <Destroy
> kill_sshkey
72 wm title
$w [mc
"Your OpenSSH Public Key"]
73 tk::PlaceWindow $w widget .
77 proc make_ssh_key
{w
} {
78 global sshkey_title sshkey_output sshkey_fd
80 set sshkey_title
[mc
"Generating..."]
81 $w.header.gen configure
-state disabled
83 set cmdline
[list sh
-c {echo | ssh-keygen
-q -t rsa
-f ~
/.ssh
/id_rsa
2>&1}]
85 if {[catch { set sshkey_fd
[_open_stdout_stderr
$cmdline] } err
]} {
86 error_popup
[mc
"Could not start ssh-keygen:\n\n%s" $err]
91 fconfigure $sshkey_fd -blocking 0
92 fileevent $sshkey_fd readable
[list read_sshkey_output
$sshkey_fd $w]
97 if {![info exists sshkey_fd
]} return
98 catch { kill_file_process
$sshkey_fd }
99 catch { close $sshkey_fd }
102 proc read_sshkey_output
{fd w
} {
103 global sshkey_fd sshkey_output sshkey_title
105 set sshkey_output
"$sshkey_output[read $fd]"
106 if {![eof $fd]} return
108 fconfigure $fd -blocking 1
111 $w.contents configure
-state normal
112 if {[catch {close $fd} err
]} {
113 set sshkey_title
[mc
"Generation failed."]
114 $w.contents insert end
$err
115 $w.contents insert end
"\n"
116 $w.contents insert end
$sshkey_output
118 set finfo
[find_ssh_key
]
120 set sshkey_title
[mc
"Generation succeded, but no keys found."]
121 $w.contents insert end
$sshkey_output
123 set sshkey_title
[mc
"Your key is in: %s" [lindex $finfo 0]]
124 $w.contents insert end
[lindex $finfo 1] sel
127 $w.contents configure
-state disable