Skip to content

Commit e148a55

Browse files
committed
utils.lua: add this script
Add a script with 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. Other future script bindings that don't fit anywhere else can also be added to utils.lua.
1 parent 1b231b4 commit e148a55

File tree

12 files changed

+116
-2
lines changed

12 files changed

+116
-2
lines changed

DOCS/interface-changes/utils.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add `--load-utils` option

DOCS/man/mpv.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,6 +1547,8 @@ works like in older mpv releases:
15471547

15481548
.. include:: positioning.rst
15491549

1550+
.. include:: utils.rst
1551+
15501552
.. include:: lua.rst
15511553

15521554
.. include:: javascript.rst

DOCS/man/options.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,10 @@ Program Behavior
10701070
Enable the builtin script that provides various keybindings to pan videos
10711071
and images (default: yes).
10721072

1073+
``--load-utils=<yes|no>``
1074+
Enable the builtin script that provides miscellaneous script bindings
1075+
(default: yes).
1076+
10731077
``--player-operation-mode=<cplayer|pseudo-gui>``
10741078
For enabling "pseudo GUI mode", which means that the defaults for some
10751079
options are changed. This option should not normally be used directly, but

DOCS/man/utils.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
UTILS
2+
=====
3+
4+
This script provides miscellaneous script bindings. It can be disabled using the
5+
``--load-utils=no`` option.
6+
7+
Script bindings
8+
---------------
9+
10+
``edit-config-file``
11+
Open ``mpv.conf`` in the system text editor, creating it if it doesn't
12+
already exist.
13+
14+
``edit-input-conf``
15+
Open ``input.conf`` in the system text editor, creating it if it doesn't
16+
already exist.

options/options.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,7 @@ static const m_option_t mp_opts[] = {
556556
{"load-select", OPT_BOOL(lua_load_select), .flags = UPDATE_BUILTIN_SCRIPTS},
557557
{"load-positioning", OPT_BOOL(lua_load_positioning), .flags = UPDATE_BUILTIN_SCRIPTS},
558558
{"load-commands", OPT_BOOL(lua_load_commands), .flags = UPDATE_BUILTIN_SCRIPTS},
559+
{"load-utils", OPT_BOOL(lua_load_utils), .flags = UPDATE_BUILTIN_SCRIPTS},
559560
#endif
560561

561562
// ------------------------- stream options --------------------
@@ -990,6 +991,7 @@ static const struct MPOpts mp_default_opts = {
990991
.lua_load_select = true,
991992
.lua_load_positioning = true,
992993
.lua_load_commands = true,
994+
.lua_load_utils = true,
993995
#endif
994996
.auto_load_scripts = true,
995997
.loop_times = 1,

options/options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ typedef struct MPOpts {
176176
bool lua_load_select;
177177
bool lua_load_positioning;
178178
bool lua_load_commands;
179+
bool lua_load_utils;
179180

180181
bool auto_load_scripts;
181182

player/core.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ typedef struct MPContext {
444444

445445
struct mp_ipc_ctx *ipc_ctx;
446446

447-
int64_t builtin_script_ids[8];
447+
int64_t builtin_script_ids[9];
448448

449449
mp_mutex abort_lock;
450450

player/lua.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ static const char * const builtin_lua_scripts[][2] = {
9090
},
9191
{"@commands.lua",
9292
# include "player/lua/commands.lua.inc"
93+
},
94+
{"@utils.lua",
95+
# include "player/lua/utils.lua.inc"
9396
},
9497
{0}
9598
};

player/lua/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
lua_files = ['defaults.lua', 'assdraw.lua', 'options.lua', 'osc.lua',
22
'ytdl_hook.lua', 'stats.lua', 'console.lua', 'auto_profiles.lua',
33
'input.lua', 'fzy.lua', 'select.lua', 'positioning.lua',
4-
'commands.lua']
4+
'commands.lua', 'utils.lua']
55
foreach file: lua_files
66
lua_file = custom_target(file,
77
input: file,

player/lua/select.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,8 @@ mp.add_key_binding(nil, "menu", function ()
620620
{"Watch later", "script-binding select/select-watch-later", true},
621621
{"Stats for nerds", "script-binding stats/display-page-1-toggle", true},
622622
{"File info", "script-binding stats/display-page-5-toggle", mp.get_property("filename")},
623+
{"Edit config file", "script-binding utils/edit-config-file", true},
624+
{"Edit key bindings", "script-binding utils/edit-input-conf", true},
623625
{"Help", "script-binding stats/display-page-4-toggle", true},
624626
}
625627

0 commit comments

Comments
 (0)