@@ -25,6 +25,15 @@ local options = {
25
25
26
26
require " mp.options" .read_options (options , nil , function () end )
27
27
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
+
28
37
local function show_warning (message )
29
38
mp .msg .warn (message )
30
39
if mp .get_property_native (" vo-configured" ) then
@@ -580,6 +589,48 @@ mp.add_key_binding(nil, "show-properties", function ()
580
589
})
581
590
end )
582
591
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
+
583
634
mp .add_key_binding (nil , " menu" , function ()
584
635
local sub_track_count = 0
585
636
local audio_track_count = 0
@@ -620,6 +671,8 @@ mp.add_key_binding(nil, "menu", function ()
620
671
{" Watch later" , " script-binding select/select-watch-later" , true },
621
672
{" Stats for nerds" , " script-binding stats/display-page-1-toggle" , true },
622
673
{" 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 },
623
676
{" Help" , " script-binding stats/display-page-4-toggle" , true },
624
677
}
625
678
0 commit comments