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

Platform-specific keymap #1561

Closed hongyuanjia closed 2 weeks ago

hongyuanjia commented 2 weeks ago

yazi --debug output

❯ yazi --debug

Yazi
    Version: 0.3.0 (7a380c2 2024-08-01)
    Debug  : false
    OS     : windows-x86_64 (windows)

Ya
    Version: 0.3.0

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

Adapter
    Adapter.matches: Iterm2

Desktop
    XDG_SESSION_TYPE: None
    WAYLAND_DISPLAY : None
    DISPLAY         : None

SSH
    shared.in_ssh_connection: false

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

Variables
    SHELL              : None
    EDITOR             : None
    YAZI_FILE_ONE      : Some("C:\\Users\\hongyuanjia\\scoop\\apps\\git\\current\\usr\\bin\\file.exe")
    YAZI_CONFIG_HOME   : None
    ZELLIJ_SESSION_NAME: None

Text Opener
    default: Some(Opener { run: "nvim \"%@\"", block: true, orphan: false, desc: "neovim", for_: None, spread: false })
    block  : Some(Opener { run: "nvim \"%@\"", block: true, orphan: false, desc: "neovim", for_: None, spread: false })

tmux
    TMUX   : false
    Version: program not found

Dependencies
    file             : 5.45
    ueberzugpp       : program not found
    ffmpegthumbnailer: program not found
    magick           : program not found
    fzf              : 0.53.0
    fd               : 10.1.0
    rg               : 14.1.0
    chafa            : program not found
    zoxide           : program not found
    7z               : 24.06
    7zz              : program not found
    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 "C:\\Users\\hongyuanjia\\AppData\\Roaming\\yazi\\state" directory.

Please describe the problem you're trying to solve

In yazi.toml we can have a for field to specify the settings for specific platforms, e.g.:

[opener]
edit = [
    { run = '${EDITOR:=vi} "$@"', block = true, desc = "$EDITOR", for = "unix" },
    { run = 'nvim "%@"', block = true, desc = "neovim", for = "windows" }
]

I wonder if it is possible to do the same in keymap.toml? E.g.:

[[manager]]
prepend_keymap = [
    { on = [ "<C-s>" ], run = 'shell "$SHELL" --block --confirm', desc = "Open shell here", for = "unix" },
    { on = [ "<C-s>" ], run = 'shell "pwsh" --block --confirm', desc = "Open shell here",for = "windows" }
]

Would you be willing to contribute this feature?

Describe the solution you'd like

[[manager]]
prepend_keymap = [
    { on = [ "<C-s>" ], run = 'shell "$SHELL" --block --confirm', desc = "Open shell here", for = "unix" },
    { on = [ "<C-s>" ], run = 'shell "pwsh" --block --confirm', desc = "Open shell here",for = "windows" }
]

Additional context

No response

Validations

sxyazi commented 2 weeks ago

Sorry, this is one of the features I don't want to add because it goes against Yazi's design philosophy. Yazi is meant to have consistent behavior across all platforms, so assigning different functions to the same key on different platforms would clearly violate that.

The reason we introduced for for [opener] was to hide these differences - even if the opener defines different programs, you can still use them consistently within [open]. The same goes for keybindings: if you really want to have platform-specific differences, please hide them in a plugin, here is an example https://github.com/sxyazi/yazi/issues/51#issuecomment-2256273945

hongyuanjia commented 2 weeks ago

No worry, it totally makes sense. Thanks for the hint.