-
Notifications
You must be signed in to change notification settings - Fork 4
/
shaders-rofi.lua
48 lines (42 loc) · 1.39 KB
/
shaders-rofi.lua
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
local utils = require 'mp.utils'
local options = require 'mp.options'
local shaders_dir = mp.command_native({"expand-path", "~~/shaders/"})
local function get_paths(dir)
local result = {}
local ls = utils.readdir(shaders_dir)
for i, child in pairs(ls) do
local info = utils.file_info(shaders_dir .. "/" .. child);
if info.is_dir then
for _, grandchild in pairs(get_paths(shaders_dir .. "/" .. child)) do
result[#result + 1] = grandchild
end
elseif string.match(child, "%.glsl$") or string.match(child, "%.hook$") then
result[#result + 1] = shaders_dir .. "/" .. child
end
end
return result
end
local function get_rofi_choice(lines)
local rofi = mp.command_native({
name = "subprocess",
args = { "rofi", "-dmenu", "-i" },
capture_stdout = true,
playback_only = false,
stdin_data = table.concat(lines, "\n"),
})
return rofi.stdout, rofi.status
end
local function handler()
-- mp.get_property_native("glsl-shaders")
local paths = get_paths(shaders_dir)
local names = {}
for _, path in ipairs(paths) do
table.insert(names, string.match(path, "[^/]+$"))
end
local shader, status = get_rofi_choice(names)
if status == 0 and shader then
shader = shader:gsub("^%s*(.-)%s*$", "%1")
mp.commandv("change-list", "glsl-shaders", "set", shaders_dir .. shader)
end
end
mp.add_key_binding("Ctrl+s", "shaders-rofi", handler)