select.lua: add edit-config-file and edit-input-conf
Add script bindings to edit mpv.conf and input.conf, and add them to the menu. These are useful as shortcuts, but the main motivation is that new users often ask why they can't find mpv.conf and input.conf, so this creates them if they don't exist.
This commit is contained in:
1 parent
0bbcc91e1b
commit
7c1a4acdb2
2 files changed
+56
-1
No files matched your search
@@ -127,6 +127,14 @@ Available script bindings are:
|
||||
print its value on the OSD, which is useful for long values that get
|
||||
clipped.
|
||||
|
||||
``edit-config-file``
|
||||
Open ``mpv.conf`` in the system text editor, creating it if it doesn't
|
||||
already exist.
|
||||
|
||||
``edit-input-conf``
|
||||
Open ``input.conf`` in the system text editor, creating it if it doesn't
|
||||
already exist.
|
||||
|
||||
``menu``
|
||||
Show a menu with miscellaneous entries.
|
||||
|
||||
|
||||
+48
-1
@@ -633,6 +633,51 @@ mp.add_key_binding(nil, "show-properties", function ()
|
||||
})
|
||||
end)
|
||||
|
||||
local function system_open(path)
|
||||
local platform = mp.get_property("platform")
|
||||
local args
|
||||
if platform == "windows" then
|
||||
args = {"rundll32", "url.dll,FileProtocolHandler", path}
|
||||
elseif platform == "darwin" then
|
||||
args = {"open", path}
|
||||
else
|
||||
args = {"gio", "open", path}
|
||||
end
|
||||
|
||||
mp.commandv("run", unpack(args))
|
||||
end
|
||||
|
||||
local function edit_config_file(filename)
|
||||
if not mp.get_property_bool("config") then
|
||||
show_warning("Editing config files with --no-config is not supported.")
|
||||
return
|
||||
end
|
||||
|
||||
local path = mp.find_config_file(filename)
|
||||
|
||||
if not path then
|
||||
path = mp.command_native({"expand-path", "~~/" .. filename})
|
||||
local file_handle, error_message = io.open(path, "w")
|
||||
|
||||
if not file_handle then
|
||||
show_error(error_message)
|
||||
return
|
||||
end
|
||||
|
||||
file_handle:close()
|
||||
end
|
||||
|
||||
system_open(path)
|
||||
end
|
||||
|
||||
mp.add_key_binding(nil, "edit-config-file", function ()
|
||||
edit_config_file("mpv.conf")
|
||||
end)
|
||||
|
||||
mp.add_key_binding(nil, "edit-input-conf", function ()
|
||||
edit_config_file("input.conf")
|
||||
end)
|
||||
|
||||
mp.add_key_binding(nil, "menu", function ()
|
||||
local sub_track_count = 0
|
||||
local audio_track_count = 0
|
||||
@@ -673,6 +718,8 @@ mp.add_key_binding(nil, "menu", function ()
|
||||
{"Watch later", "script-binding select/select-watch-later", true},
|
||||
{"Stats for nerds", "script-binding stats/display-page-1-toggle", true},
|
||||
{"File info", "script-binding stats/display-page-5-toggle", mp.get_property("filename")},
|
||||
{"Edit config file", "script-binding select/edit-config-file", true},
|
||||
{"Edit key bindings", "script-binding select/edit-input-conf", true},
|
||||
{"Help", "script-binding stats/display-page-4-toggle", true},
|
||||
}
|
||||
|
||||
@@ -693,7 +740,7 @@ mp.add_key_binding(nil, "menu", function ()
|
||||
submit = function (i)
|
||||
mp.command(commands[i])
|
||||
|
||||
if not commands[i]:find("^script%-binding select/") then
|
||||
if not commands[i]:find("^script%-binding select/select") then
|
||||
input.terminate()
|
||||
end
|
||||
end,
|
||||
|
||||
Reference in new issue
Block a user