Skip to content

Commit bd49303

Browse files
committed
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, also including links to the documentation.
1 parent 1b231b4 commit bd49303

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

DOCS/man/select.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,14 @@ Available script bindings are:
119119
print its value on the OSD, which is useful for long values that get
120120
clipped.
121121

122+
``edit-config-file``
123+
Open ``mpv.conf`` in the system text editor, creating it if it doesn't
124+
already exist.
125+
126+
``edit-input-conf``
127+
Open ``input.conf`` in the system text editor, creating it if it doesn't
128+
already exist.
129+
122130
``menu``
123131
Show a menu with miscellaneous entries.
124132

player/lua/select.lua

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ local options = {
2525

2626
require "mp.options".read_options(options, nil, function () end)
2727

28+
local default_config_file = [[# https://mpv.io/manual/stable/#configuration-files
29+
# https://mpv.io/manual/stable/#options
30+
31+
]]
32+
33+
local default_input_conf = [[# https://mpv.io/manual/stable/#command-interface
34+
35+
]]
36+
2837
local function show_warning(message)
2938
mp.msg.warn(message)
3039
if mp.get_property_native("vo-configured") then
@@ -580,6 +589,48 @@ mp.add_key_binding(nil, "show-properties", function ()
580589
})
581590
end)
582591

592+
local function edit_config_file(filename, initial_contents)
593+
if not mp.get_property_bool("config") then
594+
show_warning("Editing config files with --no-config is not supported.")
595+
return
596+
end
597+
598+
local path = mp.find_config_file(filename)
599+
600+
if not path then
601+
path = mp.command_native({"expand-path", "~~/" .. filename})
602+
local file_handle, error_message = io.open(path, "w")
603+
604+
if not file_handle then
605+
show_error(error_message)
606+
return
607+
end
608+
609+
file_handle:write(initial_contents)
610+
file_handle:close()
611+
end
612+
613+
local platform = mp.get_property("platform")
614+
local args
615+
if platform == "windows" then
616+
args = {"rundll32", "url.dll,FileProtocolHandler", path}
617+
elseif platform == "darwin" then
618+
args = {"open", path}
619+
else
620+
args = {"gio", "open", path}
621+
end
622+
623+
mp.commandv("run", unpack(args))
624+
end
625+
626+
mp.add_key_binding(nil, "edit-config-file", function ()
627+
edit_config_file("mpv.conf", default_config_file)
628+
end)
629+
630+
mp.add_key_binding(nil, "edit-input-conf", function ()
631+
edit_config_file("input.conf", default_input_conf)
632+
end)
633+
583634
mp.add_key_binding(nil, "menu", function ()
584635
local sub_track_count = 0
585636
local audio_track_count = 0
@@ -620,6 +671,8 @@ mp.add_key_binding(nil, "menu", function ()
620671
{"Watch later", "script-binding select/select-watch-later", true},
621672
{"Stats for nerds", "script-binding stats/display-page-1-toggle", true},
622673
{"File info", "script-binding stats/display-page-5-toggle", mp.get_property("filename")},
674+
{"Edit config file", "script-binding select/edit-config-file", true},
675+
{"Edit key bindings", "script-binding select/edit-input-conf", true},
623676
{"Help", "script-binding stats/display-page-4-toggle", true},
624677
}
625678

0 commit comments

Comments
 (0)