sxyazi / yazi

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

environment variables accessible in `shell` commands #1635

Closed Maik93 closed 3 weeks ago

Maik93 commented 3 weeks ago

yazi --debug output

Yazi
    Version: 0.3.3 (Arch Linux 2024-09-05)
    Debug  : false
    OS     : linux-x86_64 (unix)

Ya
    Version: 0.3.3 (Arch Linux 2024-09-05)

Emulator
    Emulator.via_env: ("xterm-kitty", "")
    Emulator.via_csi: Ok(Kitty)
    Emulator.detect : Kitty

Adapter
    Adapter.matches: Kitty

Desktop
    XDG_SESSION_TYPE           : Some("tty")
    WAYLAND_DISPLAY            : None
    DISPLAY                    : Some(":0")
    SWAYSOCK                   : None
    HYPRLAND_INSTANCE_SIGNATURE: None
    WAYFIRE_SOCKET             : None

SSH
    shared.in_ssh_connection: false

WSL
    WSL: false

Variables
    SHELL              : Some("/bin/zsh")
    EDITOR             : Some("nvim")
    VISUAL             : 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 })

Multiplexers
    TMUX               : false
    tmux version       : 3.4
    ZELLIJ_SESSION_NAME: None
    Zellij version     : No such file or directory (os error 2)

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

Please describe the problem you're trying to solve

Currently, the shell command (https://yazi-rs.github.io/docs/configuration/keymap/#manager.shell) does not support linux environment variables. They would be very helpful when dealing with complex keybindings.

Would you be willing to contribute this feature?

Describe the solution you'd like

I'd like to write keymaps such as run = "shell --orphan --confirm 'if [[ -n $TMUX ]]; then ...

Additional context

No response

Validations

sxyazi commented 3 weeks ago

Hi, this is a feature that's already supported, I have:

{ on = "<C-t>", run = "shell --orphan --confirm 'echo $TMUX > /tmp/test'" }, 

in my keymap.toml, when I press <C-t>, the value of $TMUX is correctly output to /tmp/test:

❯ cat /tmp/test
/private/tmp/tmux-501/default,74392,2

I'm not sure what version of Yazi you're using since you skipped yazi --debug, but please make sure it's the latest version.

Closing as already supported.

Maik93 commented 3 weeks ago

I'm not sure what I was missing, but your keymap snippet actually works both for me!

Thanks, please keep going on with this repo because it's beautiful!