6 ssh.lua - SSH menu for known hosts.
12 wmii.load_plugin ("ssh")
13 wmii.add_key_handler ("Mod1-z", ssh.show_menu)
19 This reads ~/.ssh/known_hosts in order to display a menu of hosts (and IP
20 addresses) found in the file. It assumes 'HashKnownHosts no' is set in
21 ~/.ssh/config (otherwise it displays the hashed hosts).
29 David Leadbeater <dgl@dgl.cx>
31 =head1 LICENCE AND COPYRIGHT
33 Copyright (c) 2008, David Leadbeater <dgl@dgl.cx>
35 This is free software. You may redistribute copies of it under the terms of
36 the GNU General Public License L<http://www.gnu.org/licenses/gpl.html>. There
37 is NO WARRANTY, to the extent permitted by law.
42 local wmii
= require("wmii")
43 local os
= require("os")
44 local io
= require("io")
50 wmii
.set_conf ("ssh.askforuser", true);
58 local file
= io
.open(os
.getenv("HOME") .. "/.ssh/known_hosts", "r")
60 local line
= file
:read("*line")
63 local host
= line
:match("([^ ,]+)")
65 line
= file
:read("*line")
74 local file
= io
.open("/etc/passwd", "r")
76 local line
= file
:read("*line")
80 local user
= line
:match("([^:]+)")
82 line
= file
:read("*line")
89 local str
= wmii
.menu(hosts
, "ssh:")
90 if type(str
) == "string" then
91 local cmd
= wmii
.get_conf("xterm") .. " -e /bin/sh -c \"exec ssh "
92 if wmii
.get_conf("ssh.askforuser") then
93 local user
= wmii
.menu(users
, "username:")
94 if type(user
) == "string" and user
~= "" then
95 cmd
= cmd
.. "-l " .. user
.. " "
98 cmd
= cmd
.. str
.. "\" &"