git-gui / git-gui--askpasson commit Merge git://git.kernel.org/pub/scm/gitk/gitk (b43b736)
   1#!/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
   8set answer {}
   9set yesno  0
  10set rc     255
  11
  12if {$argc < 1} {
  13        set prompt "Enter your OpenSSH passphrase:"
  14} else {
  15        set prompt [join $argv " "]
  16        if {[regexp -nocase {\(yes\/no\)\?\s*$} $prompt]} {
  17                set yesno 1
  18        }
  19}
  20
  21message .m -text $prompt -justify center -aspect 4000
  22pack .m -side top -fill x -padx 20 -pady 20 -expand 1
  23
  24entry .e -textvariable answer -width 50
  25pack .e -side top -fill x -padx 10 -pady 10
  26
  27if {!$yesno} {
  28        .e configure -show "*"
  29}
  30
  31frame .b
  32button .b.ok     -text OK     -command finish
  33button .b.cancel -text Cancel -command {destroy .}
  34
  35pack .b.ok -side left -expand 1
  36pack .b.cancel -side right -expand 1
  37pack .b -side bottom -fill x -padx 10 -pady 10
  38
  39bind . <Visibility> {focus -force .e}
  40bind . <Key-Return> finish
  41bind . <Key-Escape> {destroy .}
  42bind . <Destroy>    {exit $rc}
  43
  44proc finish {} {
  45        if {$::yesno} {
  46                if {$::answer ne "yes" && $::answer ne "no"} {
  47                        tk_messageBox -icon error -title "Error" -type ok \
  48                                -message "Only 'yes' or 'no' input allowed."
  49                        return
  50                }
  51        }
  52
  53        set ::rc 0
  54        puts $::answer
  55        destroy .
  56}
  57
  58wm title . "OpenSSH"
  59tk::PlaceWindow .