Skip to content

Instantly share code, notes, and snippets.

@fracek
Created January 5, 2013 21:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fracek/4463821 to your computer and use it in GitHub Desktop.
Save fracek/4463821 to your computer and use it in GitHub Desktop.
WeeChat plugin to store login credentials in a separate file. Create a `login` file in `~/.weechat/login` and put a connection command on each line.
irc.freenode.net -username=toethumb -autojoin=weechat,test -nicks=toethumb
irc.quakenet.org -nicks=ninjaduck,ninjaduck2 -autojoin=mmo-champion
local w = weechat -- lazy
local SCRIPT = {
name = "secretauth",
author = "Francesco Ceccon",
version = "0.1",
license = "Public Domain",
desc = "Store server credentials in a separate file"
}
w.register(SCRIPT.name, SCRIPT.author, SCRIPT.version, SCRIPT.license,
SCRIPT.desc, "", "")
-- Write an error message in the weechat buffer
function print_error(buffer, ...)
w.print(buffer, w.prefix("error") .. unpack(arg))
end
-- Expand the path if it begins with ~/
function expand_path(path)
if path:sub(1,2) == "~/" then
return os.getenv("HOME") .. path:sub(2)
end
end
-- Load config
local config = { data = {} }
setmetatable(config, {
__index = function(t, k)
return w.config_string(t.data[k])
end
})
do
config.file = w.config_new(SCRIPT.name, function(_, file)
return w.config_reload(file)
end, "")
if not config.file then return end
config.login = w.config_new_section(
config.file, "login", 0, 0, "", "", "", "", "", "", "", "", "", ""
)
local c = config.data
c.login_file = w.config_new_option(
config.file,
config.login,
"file", "string", "The file containing the login commands",
"", 0, 0, "~/.weechat/login", "~/.weechat/login", 0, "", "", "", "", "", ""
)
w.config_read(config.file)
end
w.print(nil, "Reading " .. config.login_file)
local file_path = expand_path(config.login_file)
local f = io.open(file_path, "r")
if f == nil then
print_error(nil, "Error while reading " .. file_path)
return
end
for connection in f:lines() do
w.print(nil, "Connecting to " .. connection)
w.command(nil, "/connect " .. connection)
end
f:close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment