History

command: add normalize-path command

This can be used e.g. by a bookmarking script to show normalized paths.

Guido Cella committed 2 years ago

Commit 6ec3e151 parent b6615cd3 files · +30 −0Browse files

Unified · Split

3 files
  1. DOCS/interface-changes/normalize-path.txt +1 −0
  2. DOCS/man/input.rst +15 −0
  3. player/command.c +14 −0
DOCS/interface-changes/normalize-path.txt+1−0
@@ -0,0 +1 @@
1add the `normalize-path` command
DOCS/man/input.rst+15−0
@@ -827,6 +827,21 @@ Remember to quote string arguments in input.conf (see `Flat command syntax`_). · 826 unmodified lines
827 This line of Lua would show the location of the user's mpv827 This line of Lua would show the location of the user's mpv
828 configuration directory on the OSD.828 configuration directory on the OSD.
829 829
830``normalize-path <filename>``
831 Return a canonical representation of the path ``filename`` by converting it
832 to an absolute path, removing consecutive slashes, removing ``.``
833 components, resolving ``..`` components, and converting slashes to
834 backslashes on Windows. Symlinks are not resolved unless the platform is
835 Unix-like and one of the path components is ``..``. If ``filename`` is a
836 URL, it is returned unchanged. This can only be used through the client API
837 or from a script using ``mp.command_native``.
838
839 .. admonition:: Example
840
841 ``mp.osd_message(mp.command_native({"normalize-path", "/foo//./bar"}))``
842
843 This line of Lua prints "/foo/bar" on the OSD.
844
830``escape-ass <text>``845``escape-ass <text>``
831 Modify ``text`` so that commands and functions that interpret ASS tags,846 Modify ``text`` so that commands and functions that interpret ASS tags,
832 such as ``osd-overlay`` and ``mp.create_osd_overlay``, will display it847 such as ``osd-overlay`` and ``mp.create_osd_overlay``, will display it
player/command.c+14−0
@@ -5644,6 +5644,19 @@ static void cmd_expand_path(void *p) · 5643 unmodified lines
5644 };5644 };
5645}5645}
5646 5646
5647static void cmd_normalize_path(void *p)
5648{
5649 struct mp_cmd_ctx *cmd = p;
5650 void *ctx = talloc_new(NULL);
5651
5652 cmd->result = (mpv_node){
5653 .format = MPV_FORMAT_STRING,
5654 .u.string = talloc_strdup(NULL, mp_normalize_path(ctx, cmd->args[0].v.s)),
5655 };
5656
5657 talloc_free(ctx);
5658}
5659
5647static void cmd_escape_ass(void *p)5660static void cmd_escape_ass(void *p)
5648{5661{
5649 struct mp_cmd_ctx *cmd = p;5662 struct mp_cmd_ctx *cmd = p;
@@ -6764,6 +6777,7 @@ const struct mp_cmd_def mp_cmds[] = { · 1114 unmodified lines
6764 .is_noisy = true },6777 .is_noisy = true },
6765 { "expand-path", cmd_expand_path, { {"text", OPT_STRING(v.s)} },6778 { "expand-path", cmd_expand_path, { {"text", OPT_STRING(v.s)} },
6766 .is_noisy = true },6779 .is_noisy = true },
6780 { "normalize-path", cmd_normalize_path, { {"filename", OPT_STRING(v.s)} }},
6767 { "escape-ass", cmd_escape_ass, { {"text", OPT_STRING(v.s)} },6781 { "escape-ass", cmd_escape_ass, { {"text", OPT_STRING(v.s)} },
6768 .is_noisy = true },6782 .is_noisy = true },
6769 { "show-progress", cmd_show_progress, .allow_auto_repeat = true,6783 { "show-progress", cmd_show_progress, .allow_auto_repeat = true,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t