sxyazi / yazi

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

The context menu show incorrect options in some files #700

Closed Saafo closed 8 months ago

Saafo commented 8 months ago

What system are you running Yazi on?

macOS

What terminal are you running Yazi in?

Warp / iTerm2

Yazi version

0.2.3

Did you try the latest main branch to see if the problem has already been fixed?

Not tried, and I'll explain why below

Describe the bug

Using main branch need to build yazi locally and need many dependencies. And I've checked recent open and closed issues don't include this.

The options in the open options menu of some files are incorrect, for example:

I've got a print.sh and a print.swift and their options are incorrect:

image image

Then I create a print2.sh and this time the options are correct:

image

Their attributes are basically the same:

image

Besides, I've got a mov.mp4 file and its options are incorrect either(but another file named fmp4.mp4 is correct):

image

And here is the file list in yazi:

image

It's interesting that one of the two mp4 files is yellow, and one of the two shell files is yellow. I'm using the default configuration.

Expected Behavior

All shell files and swift files should contains the $EDITOR option, and all video files should contains the play option(mpv)

To Reproduce

I've got no idea temporarily, do you have and ideas about how this happened?

Configuration

no config

Anything else?

No response

sxyazi commented 8 months ago

Please do file -bL --mime-type filename on these files, and then paste the output here.

Saafo commented 8 months ago
image
sxyazi commented 8 months ago

That's so weird, could you upload those files and let me try to reproduce it?

Saafo commented 8 months ago

Yes! It's so weird. I've tried to copy print.sh to another folder, and the options are correct. print.sh.zip

evpeople commented 8 months ago

Could this be due to extended attributes in macOS? I noticed that the output of ls -al now includes an @ symbol.

Saafo commented 8 months ago

Could this be due to extended attributes in macOS? I noticed that the output of ls -al now includes an @ symbol.

I've also thought about it but they all have macOS attrs:

image image

(I've changed the attr of print.sh, but the issue still exist.)

evpeople commented 8 months ago

image After downloading the print.sh file, I noticed such a symbol. Is this expected behavior? Initially, I thought it was because I used the / for searching, which caused this, but after exiting Yazi and searching for other files, I couldn't replicate this behavior

sxyazi commented 8 months ago

image After downloading the print.sh file, I noticed such a symbol. Is this expected behavior? Initially, I thought it was because I used the / for searching, which caused this, but after exiting Yazi and searching for other files, I couldn't replicate this behavior

Do you have Nerd Fonts installed?

evpeople commented 8 months ago

Yes, This is the result of my fc-list.

/Users/evpeople/Library/Fonts/SymbolsNerdFont-Regular.ttf: Symbols Nerd Font:style=Regular
/Users/evpeople/Library/Fonts/SymbolsNerdFontMono-Regular.ttf: Symbols Nerd Font Mono:style=Regular
/Users/evpeople/Library/Fonts/Go Mono Nerd Font Complete.ttf: GoMono Nerd Font:style=Book
/Users/evpeople/Library/Fonts/Go Mono Nerd Font Complete Mono.ttf: GoMono Nerd Font Mono:style=Book
sxyazi commented 8 months ago

What's your Nerd font version? Can it render properly, if you paste this line to your terminal?

https://github.com/sxyazi/yazi/blob/3f27532c576365bf5da4a82ee89c48a677ec498f/yazi-config/preset/theme.toml#L205

It looks like this on my side:

CleanShot 2024-02-19 at 20 17 45

sxyazi commented 8 months ago

Could this be due to extended attributes in macOS? I noticed that the output of ls -al now includes an @ symbol.

I've also thought about it but they all have macOS attrs: image image (I've changed the attr of print.sh, but the issue still exist.)

Unfortunately, I can't reproduce it by using your file, could you try building Yazi from the main branch to see if the problem still? https://yazi-rs.github.io/docs/installation#build-from-source

Saafo commented 8 months ago

Unfortunately, I can't reproduce it by using your file, could you try building Yazi from the main branch to see if the problem still? https://yazi-rs.github.io/docs/installation#build-from-source

Ok, I'll build it tomorrow. If this issue still exist, can I add some log at somewhere to find out how it happens?

evpeople commented 8 months ago

*.sh" , text = "", fg = "#4d5a5e" },

Thank you, I found out it was because I hadn't configured the nerd font for Warp that I am using.

evpeople commented 8 months ago

What's your Nerd font version? Can it render properly, if you paste this line to your terminal?

https://github.com/sxyazi/yazi/blob/3f27532c576365bf5da4a82ee89c48a677ec498f/yazi-config/preset/theme.toml#L205

It looks like this on my side:

CleanShot 2024-02-19 at 20 17 45

This is amazing, it's my first time discovering that Yazi has so many cute icons.

Saafo commented 8 months ago

Unfortunately, I can't reproduce it by using your file, could you try building Yazi from the main branch to see if the problem still? https://yazi-rs.github.io/docs/installation#build-from-source

I've build from the latest main branch, and the issue still exist. Where can I add log or do something to find out why this happens?

Saafo commented 8 months ago

@sxyazi I thought there should exist an out-of-order issue:

I add a log at here:

https://github.com/sxyazi/yazi/blob/8efafd6c9104684920c819aa3fc762d9d61689e1/yazi-core/src/manager/commands/open.rs#L96

image

and here is the result:

file mime
print.sh video/quicktime
print.swift application/octet-stream
print2.sh text/plain
mov.mp4 text/x-script.python

And here is the file list in this folder:

image
sxyazi commented 8 months ago

Please add logs next to this line and then see what happens:

https://github.com/sxyazi/yazi/blob/8efafd6c9104684920c819aa3fc762d9d61689e1/yazi-core/src/manager/commands/update_mimetype.rs#L54

Saafo commented 8 months ago

@sxyazi It's already incorrect. (some file name had been renamed because of privacy)

{
  /Users/saafo/Downloads/print.swift: "application/octet-stream",
  /Users/saafo/Downloads/mock_output.py: "image/avif",
  /Users/saafo/Downloads/usercard-detail.js: "text/plain",
  /Users/saafo/Downloads/xcb.swift: "text/plain",
  /Users/saafo/Downloads/print2.sh: "text/plain",
  /Users/saafo/Downloads/add_prefix.py: "text/x-script.python",
  /Users/saafo/Downloads/IMG_7254.AVIF: "video/quicktime",
  /Users/saafo/Downloads/mock_output.sh: "image/png",
  /Users/saafo/Downloads/mov.mp4: "text/x-script.python",
  /Users/saafo/Downloads/box4.stl: "application/octet-stream",
  /Users/saafo/Downloads/test.log: "text/plain",
  /Users/saafo/Downloads/bugheic.HEIC: "image/heic",
  /Users/saafo/Downloads/mess_thumb.png: "image/heic",
  /Users/saafo/Downloads/demo_thumb.png: "image/png",
  /Users/saafo/Downloads/somepdf.pdf: "text/x-shellscript",
  /Users/saafo/Downloads/Simulator Screen Recording.mp4: "video/mp4",
  /Users/saafo/Downloads/docckit: "application/x-mach-binary",
  /Users/saafo/Downloads/someapp.dmg: "text/x-shellscript",
  /Users/saafo/Downloads/xcb.sh: "text/plain",
  /Users/saafo/Downloads/print.sh: "video/quicktime",
}
sxyazi commented 8 months ago

Then apply this patch:

--- /yazi-plugin/preset/plugins/mime.lua
+++ /yazi-plugin/preset/plugins/mime.lua
@@ -3,6 +3,7 @@ local M = {}
 function M:preload()
    local urls = {}
    for _, file in ipairs(self.files) do
+       ya.err("file.url: " .. tostring(file.url))
        urls[#urls + 1] = tostring(file.url)
    end

@@ -33,6 +34,7 @@ function M:preload()
            break
        end

+       ya.err("next: " .. next)
        next = next:gsub("[\r\n]+$", "")
        if ya.mime_valid(next) then
            j, mimes[urls[i]] = j + 1, next

And paste your ~/.local/state/yazi/yazi.log content here

Saafo commented 8 months ago

@sxyazi

log 2024-02-20T11:05:18.952905Z ERROR yazi_plugin::utils::log: file.url: /Users/saafo/Downloads/SimulatorScreen Recording.mp4 at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.952996Z ERROR yazi_plugin::utils::log: file.url: /Users/saafo/Downloads/add_prefix.py at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.953006Z ERROR yazi_plugin::utils::log: file.url: /Users/saafo/Downloads/box4.stl at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.953014Z ERROR yazi_plugin::utils::log: file.url: /Users/saafo/Downloads/bugheic.HEIC at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.953022Z ERROR yazi_plugin::utils::log: file.url: /Users/saafo/Downloads/demo_thumb.png at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.953030Z ERROR yazi_plugin::utils::log: file.url: /Users/saafo/Downloads/docckit at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.953037Z ERROR yazi_plugin::utils::log: file.url: /Users/saafo/Downloads/fmp4.mp4 at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.953044Z ERROR yazi_plugin::utils::log: file.url: /Users/saafo/Downloads/goodheic.HEIC at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.953051Z ERROR yazi_plugin::utils::log: file.url: /Users/saafo/Downloads/IMG_7254.AVIF at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.953059Z ERROR yazi_plugin::utils::log: file.url: /Users/saafo/Downloads/mess_thumb.png at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.953066Z ERROR yazi_plugin::utils::log: file.url: /Users/saafo/Downloads/mock_output.py at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.953073Z ERROR yazi_plugin::utils::log: file.url: /Users/saafo/Downloads/mock_output.sh at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.953081Z ERROR yazi_plugin::utils::log: file.url: /Users/saafo/Downloads/mov.mp4 at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.953088Z ERROR yazi_plugin::utils::log: file.url: /Users/saafo/Downloads/someapp.dmg at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.953118Z ERROR yazi_plugin::utils::log: file.url: /Users/saafo/Downloads/print.sh at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.953126Z ERROR yazi_plugin::utils::log: file.url: /Users/saafo/Downloads/print.swift at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.953134Z ERROR yazi_plugin::utils::log: file.url: /Users/saafo/Downloads/print2.sh at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.953144Z ERROR yazi_plugin::utils::log: file.url: /Users/saafo/Downloads/test.log at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.953152Z ERROR yazi_plugin::utils::log: file.url: /Users/saafo/Downloads/usercard-detail.js at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.953159Z ERROR yazi_plugin::utils::log: file.url: /Users/saafo/Downloads/xcb.sh at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.953166Z ERROR yazi_plugin::utils::log: file.url: /Users/saafo/Downloads/xcb.swift at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.953174Z ERROR yazi_plugin::utils::log: file.url: /Users/saafo/Downloads/somepdf.pdf at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.986777Z ERROR yazi_plugin::utils::log: next: video/mp4  at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.986851Z ERROR yazi_plugin::utils::log: next: text/x-script.python  at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.986870Z ERROR yazi_plugin::utils::log: next: application/octet-stream  at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.986886Z ERROR yazi_plugin::utils::log: next: image/heic  at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.986902Z ERROR yazi_plugin::utils::log: next: image/png  at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.986914Z ERROR yazi_plugin::utils::log: next: application/x-mach-binary  at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.986926Z ERROR yazi_plugin::utils::log: next: /Users/saafo/Downloads/docckit (for architecture x86_64): application/x-mach-binary  at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.986939Z ERROR yazi_plugin::utils::log: next: /Users/saafo/Downloads/docckit (for architecture arm64): application/x-mach-binary  at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.986951Z ERROR yazi_plugin::utils::log: next: video/quicktime  at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.986962Z ERROR yazi_plugin::utils::log: next: image/heic  at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.986977Z ERROR yazi_plugin::utils::log: next: image/avif  at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.986989Z ERROR yazi_plugin::utils::log: next: image/png  at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.987003Z ERROR yazi_plugin::utils::log: next: text/x-script.python  at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.987014Z ERROR yazi_plugin::utils::log: next: text/x-shellscript  at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.987026Z ERROR yazi_plugin::utils::log: next: video/quicktime  at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.987036Z ERROR yazi_plugin::utils::log: next: application/octet-stream  at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.987047Z ERROR yazi_plugin::utils::log: next: text/plain  at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.987056Z ERROR yazi_plugin::utils::log: next: text/plain  at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.987094Z ERROR yazi_plugin::utils::log: next: text/plain  at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.987106Z ERROR yazi_plugin::utils::log: next: text/plain  at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.987115Z ERROR yazi_plugin::utils::log: next: text/plain  at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.987125Z ERROR yazi_plugin::utils::log: next: text/x-shellscript  at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.987423Z ERROR yazi_scheduler::preload::preload: Preload task `mime` returned 2 at yazi-scheduler/src/preload/preload.rs:42 2024-02-20T11:05:18.987453Z  INFO yazi_core::manager::commands::update_mimetype: mimes: ${/Users/saafo/Downloads/print2.sh: "text/plain", /Users/saafo/Downloads/xcb.sh: "text/plain", /Users/saafo/Downloads/print.swift: "application/octet-stream", /Users/saafo/Downloads/bugheic.HEIC: "image/heic", /Users/saafo/Downloads/docckit: "application/x-mach-binary", /Users/saafo/Downloads/mock_output.sh: "image/png", /Users/saafo/Downloads/someapp.dmg: "text/x-shellscript", /Users/saafo/Downloads/add_prefix.py: "text/x-script.python", /Users/saafo/Downloads/mock_output.py: "image/avif", /Users/saafo/Downloads/SimulatorScreen Recording.mp4: "video/mp4", /Users/saafo/Downloads/mov.mp4: "text/x-script.python", /Users/saafo/Downloads/test.log: "text/plain", /Users/saafo/Downloads/somepdf.pdf: "text/x-shellscript", /Users/saafo/Downloads/usercard-detail.js: "text/plain", /Users/saafo/Downloads/print.sh: "video/quicktime", /Users/saafo/Downloads/demo_thumb.png: "image/png", /Users/saafo/Downloads/mess_thumb.png: "image/heic", /Users/saafo/Downloads/xcb.swift: "text/plain", /Users/saafo/Downloads/IMG_7254.AVIF: "video/quicktime", /Users/saafo/Downloads/box4.stl: "application/octet-stream"} at yazi-core/src/manager/commands/update_mimetype.rs:55 2024-02-20T11:05:18.990559Z ERROR yazi_scheduler::preload::preload: Preload task `image` returned 2 at yazi-scheduler/src/preload/preload.rs:42 2024-02-20T11:05:18.990594Z ERROR yazi_scheduler::preload::preload: Preload task `image` returned 2 at yazi-scheduler/src/preload/preload.rs:42 2024-02-20T11:05:18.990722Z ERROR yazi_scheduler::preload::preload: Preload task `image` returned 2 at yazi-scheduler/src/preload/preload.rs:42 2024-02-20T11:05:18.993358Z ERROR yazi_plugin::utils::log: spawn `ffmpegthumbnailer` command returns 2 at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.993478Z ERROR yazi_scheduler::preload::preload: Preload task `video` returned 0 at yazi-scheduler/src/preload/preload.rs:42 2024-02-20T11:05:18.995112Z ERROR yazi_plugin::utils::log: spawn `ffmpegthumbnailer` command returns 2 at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.995315Z ERROR yazi_plugin::utils::log: spawn `ffmpegthumbnailer` command returns 2 at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.995420Z ERROR yazi_scheduler::preload::preload: Preload task `video` returned 0 at yazi-scheduler/src/preload/preload.rs:42 2024-02-20T11:05:18.996002Z ERROR yazi_plugin::utils::log: spawn `ffmpegthumbnailer` command returns 2 at yazi-plugin/src/utils/log.rs:10 2024-02-20T11:05:18.996110Z ERROR yazi_scheduler::preload::preload: Preload task `video` returned 0 at yazi-scheduler/src/preload/preload.rs:42
sxyazi commented 8 months ago

I ground it a bit, starting from the docckit file, the file generated inconsistent output lines:

/Users/saafo/Downloads/SimulatorScreen Recording.mp4  :  video/mp4
/Users/saafo/Downloads/add_prefix.py                  :  text/x-script.python
/Users/saafo/Downloads/box4.stl                       :  application/octet-stream
/Users/saafo/Downloads/bugheic.HEIC                   :  image/heic
/Users/saafo/Downloads/demo_thumb.png                 :  image/png
/Users/saafo/Downloads/docckit                        :  application/x-mach-binary
/Users/saafo/Downloads/fmp4.mp4                       :  /Users/saafo/Downloads/docckit (for architecture x86_64): application/x-mach-binary
/Users/saafo/Downloads/goodheic.HEIC                  :  /Users/saafo/Downloads/docckit (for architecture arm64): application/x-mach-binary
/Users/saafo/Downloads/IMG_7254.AVIF                  :  video/quicktime
/Users/saafo/Downloads/mess_thumb.png                 :  image/heic
/Users/saafo/Downloads/mock_output.py                 :  image/avif
/Users/saafo/Downloads/mock_output.sh                 :  image/png
/Users/saafo/Downloads/mov.mp4                        :  text/x-script.python
/Users/saafo/Downloads/someapp.dmg                    :  text/x-shellscript
/Users/saafo/Downloads/print.sh                       :  video/quicktime
/Users/saafo/Downloads/print.swift                    :  application/octet-stream
/Users/saafo/Downloads/print2.sh                      :  text/plain
/Users/saafo/Downloads/test.log                       :  text/plain
/Users/saafo/Downloads/usercard-detail.js             :  text/plain
/Users/saafo/Downloads/xcb.sh                         :  text/plain
/Users/saafo/Downloads/xcb.swift                      :  text/plain
/Users/saafo/Downloads/somepdf.pdf                    :  text/x-shellscript

What kind of file is it? Is it possible to send it to me for testing (if it is not privacy-related)?

Also please do file -bL --mime-type /Users/saafo/Downloads/demo_thumb.png /Users/saafo/Downloads/docckit /Users/saafo/Downloads/fmp4.mp4 then paste the output here.

Saafo commented 8 months ago

@sxyazi Sorry this file is privacy-related, I cannot share it. But it's a unix executable binary file compiled from swift(a command line program).

image

It seems that the docckit file is a fat/universal/multi-arch binary, so the mime result output has multi lines!

I've got another similar binary file that can be upload if you need it.

sxyazi commented 8 months ago

I've got another similar binary file that can be upload if you need it.

Yeah please upload it.

sxyazi commented 8 months ago

Hi, I made a PR trying to fix it, https://github.com/sxyazi/yazi/pull/707, let me know if it works for you!

Saafo commented 8 months ago

@sxyazi The unix executable file with multi arches support: xpm.zip

Saafo commented 8 months ago

Hi, I made a PR trying to fix it, #707, let me know if it works for you!

Oh it works! Thanks for the fix!

sxyazi commented 8 months ago

Thanks for testing! Let's merge it then

github-actions[bot] commented 7 months ago

I'm going to lock this issue because it has been closed for 30 days. ⏳ This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.