[PATCH] ssh plugin: added option to ask for a username in addition to the host

1 view
Skip to first unread message

que...@gmail.com

unread,
Oct 23, 2008, 11:16:07 AM10/23/08
to wmii...@googlegroups.com, ba...@jukie.net, Jan-David Quesel
From: Jan-David Quesel <que...@informatik.uni-oldenburg.de>

---
plugins/ssh.lua | 30 +++++++++++++++++++++++++++++-
1 files changed, 29 insertions(+), 1 deletions(-)

diff --git a/plugins/ssh.lua b/plugins/ssh.lua
index 69118b5..d6b4239 100644
--- a/plugins/ssh.lua
+++ b/plugins/ssh.lua
@@ -47,7 +47,10 @@ local type = type
module ("ssh")
api_version=0.1

+wmii.set_conf ("ssh.askforuser", "true");
+
local hosts
+local users

function load_hosts()
hosts = {}
@@ -65,12 +68,37 @@ function load_hosts()
end
end

+function load_users()
+ users = {}
+
+ local file = io.open("/etc/passwd", "r")
+ if file then
+ local line = file:read("*line")
+
+ users[""] = 1
+ while line do
+ local user = line:match("([^:]+)")
+ users[user] = 1
+ line = file:read("*line")
+ end
+ file:close()
+ end
+end
+
function show_menu()
local str = wmii.menu(hosts, "ssh:")
if type(str) == "string" then
- local cmd = wmii.get_conf("xterm") .. " -e ssh " .. str .. " &"
+ local cmd = wmii.get_conf("xterm") .. " -e /bin/sh -c \"ssh "
+ if wmii.get_conf("ssh.askforuser") == "true" then
+ local user = wmii.menu(users, "username:")
+ if type(user) == "string" and user ~= "" then
+ cmd = cmd .. "-l " .. user .. " "
+ end
+ end
+ cmd = cmd .. str .. "\" &"
os.execute(cmd)
end
end

load_hosts()
+load_users()
--
1.6.0.2

Reply all
Reply to author
Forward
0 new messages