From d000407e0fdfe42b7ddb2e093100cfd41a2eb102 Mon Sep 17 00:00:00 2001 From: Guido Cella Date: Sat, 26 Jul 2025 15:49:42 +0200 Subject: [PATCH 1/2] 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. --- DOCS/man/select.rst | 8 +++++++ player/lua/select.lua | 49 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/DOCS/man/select.rst b/DOCS/man/select.rst index 0ecb2f9b96bb2..02a3d3a367216 100644 --- a/DOCS/man/select.rst +++ b/DOCS/man/select.rst @@ -119,6 +119,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. diff --git a/player/lua/select.lua b/player/lua/select.lua index fd869e8e8cf47..85c3339cbebc8 100644 --- a/player/lua/select.lua +++ b/player/lua/select.lua @@ -580,6 +580,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 @@ -620,6 +665,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}, } @@ -640,7 +687,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, From 2375de42fb3b3f6119e076e09212531304ea4956 Mon Sep 17 00:00:00 2001 From: Guido Cella Date: Sat, 26 Jul 2025 16:51:05 +0200 Subject: [PATCH 2/2] select.lua: add online documentation menu entry --- DOCS/man/select.rst | 3 +++ player/lua/select.lua | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/DOCS/man/select.rst b/DOCS/man/select.rst index 02a3d3a367216..8b193f7dba29d 100644 --- a/DOCS/man/select.rst +++ b/DOCS/man/select.rst @@ -127,6 +127,9 @@ Available script bindings are: Open ``input.conf`` in the system text editor, creating it if it doesn't already exist. +``open-docs`` + Open mpv's online documentation in the browser. + ``menu`` Show a menu with miscellaneous entries. diff --git a/player/lua/select.lua b/player/lua/select.lua index 85c3339cbebc8..e9df4087020a9 100644 --- a/player/lua/select.lua +++ b/player/lua/select.lua @@ -625,6 +625,10 @@ mp.add_key_binding(nil, "edit-input-conf", function () edit_config_file("input.conf") end) +mp.add_key_binding(nil, "open-docs", function () + system_open("https://mpv.io/manual/") +end) + mp.add_key_binding(nil, "menu", function () local sub_track_count = 0 local audio_track_count = 0 @@ -668,6 +672,7 @@ mp.add_key_binding(nil, "menu", function () {"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}, + {"Online documentation", "script-binding select/open-docs", true}, } local labels = {}