sxyazi / yazi

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

Add support for using mime-type as the fallback for highlighting #1163

Open mikavilpas opened 3 months ago

mikavilpas commented 3 months ago

What system are you running Yazi on?

macOS

What terminal are you running Yazi in?

Wezterm

Did you try the latest code to see if this problem got fixed?

Tried, but the problem still

yazi --debug output

```sh Yazi Version: 0.2.5 (2a35d30 2024-06-17) Debug : false OS : macos-aarch64 (unix) Ya Version: 0.2.5 Emulator Emulator.via_env: ("xterm-256color", "WezTerm") Emulator.via_csi: Ok(WezTerm) Emulator.detect : WezTerm Adapter Adapter.matches: Iterm2 Desktop XDG_SESSION_TYPE: None WAYLAND_DISPLAY : None DISPLAY : Some("/private/tmp/com.apple.launchd.5hs4iDAPRl/org.xquartz:0") SSH shared.in_ssh_connection: false WSL /proc/sys/fs/binfmt_misc/WSLInterop: false Variables SHELL : Some("/bin/zsh") EDITOR : Some("nvim") ZELLIJ_SESSION_NAME: None YAZI_FILE_ONE : None YAZI_CONFIG_HOME : None Text Opener default: Some(Opener { run: "${EDITOR:=vi} \"$@\"", block: true, orphan: false, desc: "$EDITOR", for_: None, spread: true }) block : Some(Opener { run: "${EDITOR:=vi} \"$@\"", block: true, orphan: false, desc: "$EDITOR", for_: None, spread: true }) tmux TMUX : false Version: tmux 3.3a Dependencies file : 5.41 ueberzugpp : 2.9.2 ffmpegthumbnailer: 2.2.2 magick : 7.1.1-33 fzf : 0.46.1 fd : 9.0.0 rg : 14.1.0 chafa : 1.14.0 zoxide : 0.9.4 unar : 1.10.7 jq : 1.7.1 -------------------------------------------------- When reporting a bug, please also upload the `yazi.log` log file - only upload the most recent content by time. You can find it in the "/Users/mikavilpas/.local/state/yazi" directory. ```

yazi.log doesn't show anything related to this


  2024-06-17T15:35:50.436808Z  WARN yazi_adaptor::adaptor: [Adaptor] Could not identify XDG_SESSION_TYPE
    at yazi-adaptor/src/adaptor.rs:98

  2024-06-17T15:38:33.628389Z  WARN yazi_adapter::adapter: [Adapter] Could not identify XDG_SESSION_TYPE
    at yazi-adapter/src/adapter.rs:97

  2024-06-17T15:38:35.419921Z  WARN yazi_adapter::adapter: [Adapter] Could not identify XDG_SESSION_TYPE
    at yazi-adapter/src/adapter.rs:97

Describe the bug

Generally bat and yazi have similar results when highlighting a file. I noticed there are some special cases this isn't true: bat provides syntax highlighting but yazi does not highlight the syntax.

Expected Behavior

yazi shows syntax highlighting like bat

To Reproduce

For example, bat is able to highlight its own config file

image

But yazi shows this file as unhighlighted

image

Configuration

https://github.com/mikavilpas/dotfiles/blob/98e2c1122657a096425e7967a9a24c340f8f60b6/.config/yazi/yazi.toml?plain=1#L1

Anything else?

This seems to be a feature of bat, using the following heuristics that are based on file paths and names: https://github.com/sharkdp/bat/blob/c264ecd26b16ebb4f309db03d5a16b1f6e38ca67/src/syntax_mapping/builtins/README.md?plain=1#L1

I'm not sure what files are highlighted or not. As far as I can see, yazi just calls syntect to figure out what syntax should be used.

Do you think this should be fixed?

sxyazi commented 3 months ago

Nice to have, but I think it should use mine-type as the fallback rather than path as this will allow users to choose desired mime fetcher to meets their different needs

sxyazi commented 3 months ago

Or maybe only use mine-type (instead of the extension of current implementation) since it's more accurate and flexible

haennes commented 2 months ago

Hey, great project :) I have a similar problem with $ file returning test.xopp: gzip compressed data, from Unix, original size modulo 2^32 8510711 which technically is correct. (yazi unzips it succesfully and data makes sense) However I want these files (having a mimetype of application/x-xopp) to be opened by xournalpp As expected xdg-open works just fine