@@ -25,6 +25,15 @@ local options = {
2525
2626require " 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+
2837local 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 })
581590end )
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+
583634mp .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