summary refs log tree commit diff
path: root/.config/mpv/scripts/hooks.lua
blob: 81660f78b9f41dee04c84047b02426fc53e73579 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
local mp = require("mp")
local utils = require("mp.utils")

local function run(...)
	mp.msg.warn('running hooks: ' .. table.concat({ ... }, " "))
	utils.subprocess_detached({
		args = { "sh", "-c", table.concat({ ... }, " ") .. " >/dev/null 2>&1" },
		max_size = 0,
		cancellable = false,
	})
end

mp.register_event("file-loaded", function()
	local function cb(n, vo)
		if vo == true then
			run("run-parts", "-v", "--arg=file-loaded", "~/.config/mpv/hooks")
			mp.unobserve_property(cb)
		end
	end
	mp.observe_property("vo-configured", "bool", cb)
end)

mp.register_event("shutdown", function()
	run("run-parts", "-v", "--arg=shutdown", "~/.config/mpv/hooks")
end)