Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

view files in /proc #1475

Closed
2 of 3 tasks
sedlund opened this issue Aug 13, 2024 · 10 comments · Fixed by #1482
Closed
2 of 3 tasks

view files in /proc #1475

sedlund opened this issue Aug 13, 2024 · 10 comments · Fixed by #1482
Labels
feature New feature request

Comments

@sedlund
Copy link

sedlund commented Aug 13, 2024

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?

  • Yes, I'll give it a shot

Describe the solution you'd like

id like to see the contents of the file

Additional context

No response

Validations

  • I have searched the existing issues
  • The latest nightly build of Yazi doesn't already have this feature
@sedlund sedlund added the feature New feature request label Aug 13, 2024
@sxyazi
Copy link
Owner

sxyazi commented Aug 13, 2024

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

# Fallback
{ name = "*", run = "file" },

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

function M:peek()
local cmd = os.getenv("YAZI_FILE_ONE") or "file"
local output, code = Command(cmd):args({ "-bL", tostring(self.file.url) }):stdout(Command.PIPED):output()

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

@sxyazi sxyazi added the waiting on op Waiting for more information from the original poster label Aug 13, 2024
@sedlund
Copy link
Author

sedlund commented Aug 13, 2024

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.

@github-actions github-actions bot removed the waiting on op Waiting for more information from the original poster label Aug 13, 2024
@sxyazi
Copy link
Owner

sxyazi commented Aug 13, 2024

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?

@sxyazi sxyazi added the waiting on op Waiting for more information from the original poster label Aug 13, 2024
@sedlund
Copy link
Author

sedlund commented Aug 13, 2024

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).

@github-actions github-actions bot removed the waiting on op Waiting for more information from the original poster label Aug 13, 2024
@sxyazi
Copy link
Owner

sxyazi commented Aug 13, 2024

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
Copy link
Author

sedlund commented Aug 13, 2024

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
Copy link
Owner

sxyazi commented Aug 14, 2024

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
Copy link
Owner

sxyazi commented Aug 14, 2024

Please try #1482

@sedlund
Copy link
Author

sedlund commented Aug 14, 2024

works great! Thanks!

Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature New feature request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants