@@ -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/master/#configuration-files
29+ # https://mpv.io/manual/master/#options
30+
31+ ]]
32+
33+ local default_input_conf = [[ # https://mpv.io/manual/master/#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,54 @@ mp.add_key_binding(nil, "show-properties", function ()
580589 })
581590end )
582591
592+ local function edit_config_file (filename , initial_contents )
593+ local path = mp .find_config_file (filename )
594+
595+ if not path then
596+ path = mp .command_native ({" expand-path" , " ~~/" .. filename })
597+ local file_handle , error_message = io.open (path , " w" )
598+
599+ if not file_handle then
600+ show_error (error_message )
601+ return
602+ end
603+
604+ file_handle :write (initial_contents )
605+ file_handle :close ()
606+ end
607+
608+ local platform = mp .get_property (" platform" )
609+ local args
610+ if platform == " windows" then
611+ args = {" rundll32" , " url.dll,FileProtocolHandler" , path }
612+ elseif platform == " darwin" then
613+ args = {" open" , path }
614+ else
615+ args = {" xdg-open" , path }
616+ end
617+
618+ local result = mp .command_native ({
619+ name = " subprocess" ,
620+ playback_only = false ,
621+ args = args ,
622+ })
623+
624+ if result .status < 0 then
625+ show_error (" Subprocess error: " .. result .error_string )
626+ elseif result .status > 0 then
627+ show_error (utils .to_string (args ) .. " failed with code " ..
628+ result .status )
629+ end
630+ end
631+
632+ mp .add_key_binding (nil , " edit-config-file" , function ()
633+ edit_config_file (" mpv.conf" , default_config_file )
634+ end )
635+
636+ mp .add_key_binding (nil , " edit-input-conf" , function ()
637+ edit_config_file (" input.conf" , default_input_conf )
638+ end )
639+
583640mp .add_key_binding (nil , " menu" , function ()
584641 local sub_track_count = 0
585642 local audio_track_count = 0
@@ -620,6 +677,8 @@ mp.add_key_binding(nil, "menu", function ()
620677 {" Watch later" , " script-binding select/select-watch-later" , true },
621678 {" Stats for nerds" , " script-binding stats/display-page-1-toggle" , true },
622679 {" File info" , " script-binding stats/display-page-5-toggle" , mp .get_property (" filename" )},
680+ {" Edit config file" , " script-binding select/edit-config-file" , true },
681+ {" Edit key bindings" , " script-binding select/edit-input-conf" , true },
623682 {" Help" , " script-binding stats/display-page-4-toggle" , true },
624683 }
625684
0 commit comments