Software /
code /
clix
Changeset
171:eb7625161d76
clix.lua: Read resouce from config file.
author | Trần H. Trung <xmpp:trần.h.trung@trung.fun> |
---|---|
date | Fri, 07 Jul 2023 22:11:47 +0700 |
parents | 170:0d561f921c13 |
children | 172:becd3aa26e6f |
files | clix.lua |
diffstat | 1 files changed, 21 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/clix.lua Sat Jun 24 09:59:07 2023 +0200 +++ b/clix.lua Fri Jul 07 22:11:47 2023 +0700 @@ -10,7 +10,7 @@ -- Global to allow commands to add to it short_opts = { v = "verbose", q = "quiet", t = "to", f = "from", e = "type", a = "account", p = "password", r = "resource", o = "presence", c = "chatroom", i = "interactive", - f = "file" } + f = "file" } local commands = "adhoc archive avatar bounce export mirror moderate ping\ @@ -27,15 +27,24 @@ end local accounts = { default = {} }; -local current_account; - -local config_path = (os.getenv("XDG_CONFIG_HOME") or (os.getenv("HOME").."/.config")); -local config_file, err = io.open(config_path.."/.clixrc") or io.open(config_path.."/.clix"); +local current_account, config_file, err; -if not config_file then - print("Unable to open config file... looked for "..config_path.."/.clixrc"); - if err then print(err); end - os.exit(1); +local home_dir = (os.getenv("XDG_CONFIG_HOME") or os.getenv("HOME")); +if home_dir then + local config_path = (home_dir.."/.config"); + config_file, err = io.open(config_path.."/.clixrc") or io.open(config_path.."/.clix"); + if not config_file then + print("Unable to open config file... looked for "..config_path.."/.clixrc"); + if err then print(err); end + os.exit(1); + end +else + config_file, err = io.open("/etc/clixrc") or io.open("/etc/clix"); + if not config_file then + print("Could not find any config file."); + if err then print(err); end + os.exit(1); + end end for line in config_file:lines() do @@ -131,8 +140,10 @@ conn:connect_client(account.jid, account.password, clientkey, serverkey); if type(opts.resource) == "string" then conn.resource = opts.resource; + elseif account.resource then + conn.resource = account.resource; end - + local ok, ret = pcall(verse.loop); if not ok and not ret:match("interrupted!$") then io.stderr:write("Fatal error: ", ret, "\n");