aboutsummaryrefslogtreecommitdiffstats
path: root/eatit.lua
diff options
context:
space:
mode:
authorSquibid <me@zacharyscheiman.com>2023-06-29 20:35:25 -0400
committerSquibid <me@zacharyscheiman.com>2023-06-29 20:35:25 -0400
commit9d2494be1ef0d1d9d0fb014d8383a4dac114efcb (patch)
tree6f63c6ed4fd5d6a6a16e04dfa61cb6c308b61967 /eatit.lua
downloadeat-it-9d2494be1ef0d1d9d0fb014d8383a4dac114efcb.tar.gz
eat-it-9d2494be1ef0d1d9d0fb014d8383a4dac114efcb.tar.bz2
eat-it-9d2494be1ef0d1d9d0fb014d8383a4dac114efcb.zip
inital commit with the plugin working (enough)
see README for todo list and naming
Diffstat (limited to '')
-rw-r--r--eatit.lua94
1 files changed, 94 insertions, 0 deletions
diff --git a/eatit.lua b/eatit.lua
new file mode 100644
index 0000000..29f84f8
--- /dev/null
+++ b/eatit.lua
@@ -0,0 +1,94 @@
+local mp = require('mp')
+
+-- TODO: Move plugins (and opts) table to seperate file so that we can auto update without
+-- messing with the user's configs
+local plugins = { -- the plugins you want to load
+ -- link to repo file dest dir
+ -- { 'https://git.squi.bid/eat-it', 'eatit.lua', 'scripts' }, -- this is an example uncommenting it (and updating) will overwrite your config
+}
+
+-- options for eat it
+local opts = {
+ logging = { -- options for logging
+ log = true,
+ logdate = '[%H:%M:%S]:',
+ logfile = '~~/eatit.log',
+ },
+ dl = { -- options for dealing with the git repos
+ dir = '/tmp/mpv-eatit',
+ powerwash = false, -- if true the tmp dir gets deleted after mpv closes
+ }
+}
+
+local function tablelength(T)
+ local count = 0
+ for _ in pairs(T) do count = count + 1 end
+ return count
+end
+
+local function logwrite(string)
+ if opts.logging.log then
+ io.write(os.date(opts.logging.logdate) .. ' ' .. string .. '\n')
+ end
+end
+
+local function getgit()
+ os.execute('mkdir -p ' .. opts.dl.dir)
+
+ logwrite('Starting Download...')
+ for i in pairs(plugins) do
+ logwrite('downloading ' .. plugins[i][1])
+
+ -- construct the git cmd
+ local cmd = 'git -C ' .. opts.dl.dir .. ' clone ' .. plugins[i][1]
+
+ -- run the command and get the result for logging
+ local run = io.popen(cmd)
+ -- BUG: logwriting the git command doens't actually log the output
+ -- (commented out for now)
+ -- logwrite(run:read('*a'))
+ run:close()
+
+ -- get the file's dir
+ local pluginfile = opts.dl.dir .. '/' ..
+ string.match(plugins[i][1], '/([^/]+)$') ..
+ '/' .. plugins[i][2]
+
+ -- get the dest dir
+ local destfile = mp.command_native({'expand-path', '~~/'}) ..
+ '/' .. plugins[i][3] ..
+ '/' .. plugins[i][2]
+
+ -- copy the file contents over to the desired location
+ local infile = io.open(pluginfile, 'r')
+ local outfile = io.open(destfile, 'w')
+ outfile:write(infile:read('*a'))
+ outfile:close()
+ infile:close()
+ 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
+
+ logwrite('# of plugins defined in table: ' .. tablelength(plugins))
+ getgit()
+
+ -- closing/removing everything
+ if opts.dl.powerwash == true then
+ logwrite('powerwashing the tmp dir (' .. opts.dl.dir .. ')')
+ os.execute('rm -rf ' .. opts.dl.dir)
+ end
+ if opts.logging.log then
+ io.close(f)
+ end
+end
+
+mp.add_key_binding('U', 'UpdatePlugins', init)