# HG changeset patch # User Trần H. Trung # Date 1688742707 -25200 # Node ID eb7625161d76f5d708436e5acdbab209c986c951 # Parent 0d561f921c134aee911a8e875e9edef2ae3bd1b9 clix.lua: Read resouce from config file. diff -r 0d561f921c13 -r eb7625161d76 clix.lua --- 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");