Created
January 5, 2013 21:35
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
irc.freenode.net -username=toethumb -autojoin=weechat,test -nicks=toethumb | |
irc.quakenet.org -nicks=ninjaduck,ninjaduck2 -autojoin=mmo-champion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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