From 1d5e908b77f4820b6d14a4faef285bd3b59bb62d Mon Sep 17 00:00:00 2001 From: Squibid Date: Mon, 3 Jul 2023 15:54:57 -0400 Subject: simplify and rename the init function --- eatit.lua | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'eatit.lua') diff --git a/eatit.lua b/eatit.lua index 53c6856..c7053e4 100644 --- a/eatit.lua +++ b/eatit.lua @@ -37,6 +37,22 @@ local function logwrite(string) end end +local function openlog() + if opts.logging.log then -- log if asked to + -- get our logfile's full path + fn = mp.command_native({'expand-path', opts.logging.logfile}) + + f = io.open(fn, 'a') -- open file buffer + io.output(f) -- set it as default + end +end + +local function closelog() + if opts.logging.log then + io.close(f) + end +end + -- get the requested git repos local function clonegit(i) logwrite('downloading ' .. plugins[i][1]) @@ -127,15 +143,8 @@ local function startinstall() end end -local function init() - if opts.logging.log then -- log if asked to - -- get our logfile's full path - local fn = mp.command_native({'expand-path', opts.logging.logfile}) - - os.remove(fn) -- remove logfile so that we start fresh - f = io.open(fn, 'a') -- open file buffer - io.output(f) -- set it as default - end +local function initupdate() + openlog() logwrite('# of plugins defined in table: ' .. tablelength(plugins)) os.execute('mkdir -p ' .. opts.dl.dir) -- make download dir @@ -146,9 +155,9 @@ local function init() logwrite('powerwashing the tmp dir (' .. opts.dl.dir .. ')') os.execute('rm -rf ' .. opts.dl.dir) end - if opts.logging.log then - io.close(f) + + closelog() end end -mp.add_key_binding('U', 'UpdatePlugins', init) +mp.add_key_binding('U', 'UpdatePlugins', initupdate) -- cgit v1.2.1