diff options
| author | Robert Günzler <r@gnzler.io> | 2024-11-25 13:30:08 +0100 |
|---|---|---|
| committer | Robert Günzler <r@gnzler.io> | 2024-11-25 13:58:25 +0100 |
| commit | 18e3848110da0a59843058927ea04b496f5db2a5 (patch) | |
| tree | d54e7e1ab025d61507a0b1c3523c08abf400575d /.config/mpv/scripts | |
| parent | 8f29be993dad465c1bb108462dc1bd63706649a5 (diff) | |
update mpv config
Signed-off-by: Robert Günzler <r@gnzler.io>
Diffstat (limited to '.config/mpv/scripts')
| -rw-r--r-- | .config/mpv/scripts/hooks.lua | 29 | ||||
| -rw-r--r-- | .config/mpv/scripts/openuri.lua | 42 | ||||
| -rw-r--r-- | .config/mpv/scripts/yanky.lua | 4 |
3 files changed, 75 insertions, 0 deletions
diff --git a/.config/mpv/scripts/hooks.lua b/.config/mpv/scripts/hooks.lua new file mode 100644 index 0000000..902846e --- /dev/null +++ b/.config/mpv/scripts/hooks.lua @@ -0,0 +1,29 @@ +local mp = require("mp") +local utils = require("mp.utils") + +local run = function(...) + utils.subprocess_detached({ + args = { "sh", "-c", table.concat({ ... }, " ") .. " >/dev/null 2>&1" }, + max_size = 0, + cancellable = false, + }) +end + +local has_video = function() + local v = mp.get_property("video") + return v and v ~= "no" and v ~= "" +end + +mp.register_event("start-file", function() + run("makoctl", "mode", "-a", "off") + if has_video() then + run("svdn", "wlsunset") + end +end) + +mp.register_event("shutdown", function() + run("makoctl", "mode", "-r", "off") + if has_video() then + run("svup", "wlsunset") + end +end) diff --git a/.config/mpv/scripts/openuri.lua b/.config/mpv/scripts/openuri.lua new file mode 100644 index 0000000..61b20e5 --- /dev/null +++ b/.config/mpv/scripts/openuri.lua @@ -0,0 +1,42 @@ +mp = require("mp") +format_json = require("mp.utils").format_json + +function open_uri() + local json = format_json({ + type = "open-uri", + title = "https://mpv.io", + items = { + { + title = "Enter a network url", + align = "left", + value = "ignore", + muted = true, + selectable = false + } + }, + on_search = { "script-message-to", mp.get_script_name(), "openuri-cb" }, + palette = true, + search_style = "palette", + search_debounce = "submit" + }) or "{}" + mp.commandv("script-message-to", "uosc", "open-menu", json) +end + +mp.register_script_message("openuri-cb", function(path) + mp.commandv("script-message-to", "uosc", "close-menu", "openuri") + mp.commandv("loadfile", path, "append-play") +end) + +mp.add_key_binding("ctrl+o", "openuri", open_uri) + +mp.add_key_binding("ctrl+shift+o", "pasteuri", function() + local r = mp.command_native({ + name = "subprocess", + playback_only = false, + capture_stdout = true, + args = { "wl-paste" }, + }) + if r.status == 0 then + mp.commandv("script-message-to", mp.get_script_name(), "openuri-cb", r.stdout) + end +end) diff --git a/.config/mpv/scripts/yanky.lua b/.config/mpv/scripts/yanky.lua index ded6ba0..be9d308 100644 --- a/.config/mpv/scripts/yanky.lua +++ b/.config/mpv/scripts/yanky.lua @@ -12,6 +12,10 @@ end function yankpath() local path = mp.get_property_native("path") + if path ~= "^http" then + yank(path) + return + end local cwd = mp.get_property_native("working-directory") yank(require("mp.utils").join_path(cwd, path)) end |