sxyazi / yazi

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

view files in /proc #1475

Closed sedlund closed 1 month ago

sedlund commented 1 month ago

yazi --debug output

^[P>|WezTerm 20240203-110809-5046fc22^[\^[P>|WezTerm 20240203-110809-5046fc22^[\^[P>|WezTerm 20240203-110809-5046fc22^[\^[P>|WezTerm 20240203-110809-5046fc22^[\
Yazi
    Version: 0.3.0 (Nixpkgs 2024-08-01)
    Debug  : false
    OS     : linux-x86_64 (unix)

Ya
    Version: 0.3.0

Emulator
    Emulator.via_env: ("tmux-256color", "tmux")
    Emulator.via_csi: Ok(WezTerm)
    Emulator.detect : Unknown([])

Adapter
    Adapter.matches: Wayland

Desktop
    XDG_SESSION_TYPE: None
    WAYLAND_DISPLAY : Some("wayland-0")
    DISPLAY         : Some(":0")

SSH
    shared.in_ssh_connection: false

WSL
    /proc/sys/fs/binfmt_misc/WSLInterop: true

Variables
    SHELL              : Some("/run/current-system/sw/bin/zsh")
    EDITOR             : Some("lvim")
    YAZI_FILE_ONE      : None
    YAZI_CONFIG_HOME   : None
    ZELLIJ_SESSION_NAME: 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   : true
    Version: 3.4

Dependencies
    file             : 5.45
    ueberzugpp       : No such file or directory (os error 2)
    ffmpegthumbnailer: 2.2.2
    magick           : 7.1.1-36
    fzf              : 0.54.3
    fd               : 10.1.0
    rg               : 14.1.0
    chafa            : 1.14.2
    zoxide           : 0.9.4
    7z               : No such file or directory (os error 2)
    7zz              : 24.07
    jq               : 1.7.1

Please describe the problem you're trying to solve

when browsin /proc I'd like to be able to preview the contents of the virtual files. currently yazi shows them as empty

for example lf displays their content in preview.

Would you be willing to contribute this feature?

Describe the solution you'd like

id like to see the contents of the file

Additional context

No response

Validations

sxyazi commented 1 month ago

Yazi uses file -bL to preview any files that don't match a preview rule:

https://github.com/sxyazi/yazi/blob/71d6b0d9f2c49ba093b59668ebb1b6fa78afb56b/yazi-config/preset/yazi.toml#L125-L126

If we want to support /proc, this means we would need to detect this type of file in the file.lua previewer:

https://github.com/sxyazi/yazi/blob/71d6b0d9f2c49ba093b59668ebb1b6fa78afb56b/yazi-plugin/preset/plugins/file.lua#L3-L5

But I'm not sure if there's any way to do that. Any ideas?

sedlund commented 1 month ago

maybe implement some logic about the filesystem type its browsing would be good.

if its proc it could just display the text of filenames without extensions (ie: not /proc/config.gz).

this would also solve another issue i have on rclone mount filesystems (type: fuse.rclone) where yazi tries to run file on huge buckets of images to get mimetypes causing huge amount of network io.

sxyazi commented 1 month ago

maybe implement some logic about the filesystem type its browsing would be good.

I'm not sure I understand you correctly - do you mean that /proc is mounted on a different filesystem?

if its proc it could just display the text of filenames without extensions (ie: not /proc/config.gz).

Are you saying to use the filename as the preview content on the right pane?

sedlund commented 1 month ago

do you mean that /proc is mounted on a different filesystem?

it is a virtual filesystem of type proc in Linux to access configuration of the kernel.

> grep proc /proc/mounts
proc /proc proc rw,nosuid,nodev,noexec,noatime 0 0

Are you saying to use the filename as the preview content on the right pane?

Sorry, no. In /proc regular files of 0 size without extensions are virtual hooks into kernel paramaters - the content of the file can just be output to the right pane. I don't know if this is the exact specification. But /proc/config.gz is a gzipped virtual file (binary with a size of 25K on my current system) of the configuration that the running kernel was compiled with - which should not be previewed in the right pane (unless it could be decompressed, which would be nice).

sxyazi commented 1 month ago

Does this mean that all Unix-like systems have a /proc directory, and if we need to get mount info through /proc/mounts first, it is guaranteed to be present?

I noticed that there are some directories in /proc, and some files in these directories seem to contain binary content. Is there a way to detect this, for example cat /proc/bus/pci/0000:00/00.0?

sedlund commented 1 month ago

Does this mean that all Unix-like systems have a /proc directory most do (*bsd, solaris, aix, hpux) I read that macos has a /dev/proc

if we need to get mount info through /proc/mounts first, it is guaranteed to be present?

on linux the mount command reads /proc/mounts and formats that output. /proc will be present and is utilized by many *nix tools. macos has a mount command as well, i don't know how it reads its mounts from the kernel.

maybe there is an OS independent rust crate that does all this.

some files in these directories seem to contain binary content. Is there a way to detect this, for example cat /proc/bus/pci/0000:00/00.0

I see. those files have size > 0. the 'lf' file browser shows them as binary.

maybe if it's a regular file and 0 size, just cat it, if it has size, run file on it.

sxyazi commented 1 month ago

It looks like macOS doesn't implement /proc https://superuser.com/questions/631693/where-is-the-proc-folder-on-mac-os-x. I'll create a PR later to implement it just for Linux.

sxyazi commented 1 month ago

Please try https://github.com/sxyazi/yazi/pull/1482

sedlund commented 1 month ago

works great! Thanks!

github-actions[bot] commented 3 days 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.