sxyazi / yazi

💥 Blazing fast terminal file manager written in Rust, based on async I/O.
https://yazi-rs.github.io
MIT License
16.85k stars 392 forks source link

fix!: eliminate the `x-` prefix in mime-types #1927

Closed sxyazi closed 4 days ago

sxyazi commented 4 days ago

This PR aims to fully resolve discrepancies across different versions of file(1).

Specifically, Yazi uses the command file -bL --mime-type to retrieve the mime-type of files. However, different versions of file may return the same mime-type in different formats.

Older versions include the x- prefix:

❯ file -bL --mime-type test.tar.gz
application/x-gzip

while newer versions omit it:

❯ file -bL --mime-type test.tar.gz
application/gzip

This can cause inconsistent behavior when the same Yazi configuration is used across systems with different file versions, potentially breaking normal functionality.

Since the x- prefix has been discouraged as per rfc6838#section-3.4, this PR addresses the issue in the builtin mime plugin by replacing all occurrences of "x-" with an empty string ("") to unify them

⚠️ Breaking change

After this PR, all mime-types will no longer include the x- prefix, please remove it from your yazi.toml and theme.toml, for example:

# yazi.toml
[open]
- { mime = "application/x-{tar,bzip*,7z-compressed,xz,rar}", fg = "red" },
+ { mime = "application/{tar,bzip*,7z-compressed,xz,rar}", fg = "red" },
# theme.toml
[filetype]
- { mime = "application/x-{tar,bzip*,7z-compressed,xz,rar}", fg = "red" },
+ { mime = "application/{tar,bzip*,7z-compressed,xz,rar}", fg = "red" },

To help users migrate their configurations more easily, I added support for the "spotter" in https://github.com/sxyazi/yazi/pull/1802 — press Tab key on a file to open the spot window, where you can view or copy the file's new mime-type.