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

shell command in api #2295

Open
2 of 3 tasks
raymondsvendsen opened this issue Feb 5, 2025 · 4 comments
Open
2 of 3 tasks

shell command in api #2295

raymondsvendsen opened this issue Feb 5, 2025 · 4 comments
Labels
feature New feature request

Comments

@raymondsvendsen
Copy link

yazi --debug output

yazi --debug

Yazi
    Version: 0.4.3 (Arch Linux 2025-02-04)
    Debug  : false
    Triple : x86_64-unknown-linux-gnu (linux-x86_64)
    Rustc  : 1.84.1 (e71f9a9a 2025-01-27)

Ya
    Version: 0.4.3 (Arch Linux 2025-02-04)

Emulator
    TERM                : Some("st-256color")
    TERM_PROGRAM        : None
    TERM_PROGRAM_VERSION: None
    Brand.from_env      : None
    Emulator.detect     : Emulator { kind: Right(Unknown { kgp: false, sixel: false }), light: false, cell_size: None }
    Emulator.detect_full: Ok(Emulator { kind: Right(Unknown { kgp: false, sixel: false }), light: false, cell_size: None })

Adapter
    Adapter.matches: X11

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

Neovim
    NVIM          : false
    Neovim version: 0.10.4

Variables
    SHELL           : Some("/bin/zsh")
    EDITOR          : Some("nvim")
    VISUAL          : Some("nvim")
    YAZI_FILE_ONE   : None
    YAZI_CONFIG_HOME: None
    YAZI_ZOXIDE_OPTS: None
    FZF_DEFAULT_OPTS: Some("--no-mouse --height 50% -1 --reverse --multi --inline-info --preview=\'[[ $(file --mime {}) =~ binary ]] && echo {} is a binary file || (bat --style=numbers --color=always {} || cat {}) 2> /dev/null | head -300\' --preview-window=\'right:hidden:wrap\' --bind=\'f3:execute(bat --style=numbers {} || less -f {}),f2:toggle-preview,ctrl-d:half-page-down,ctrl-u:half-page-up,ctrl-a:select-all+accept,ctrl-y:execute-silent(echo {+} | xsel --clipboard --input)\'")

Text Opener
    default     : Some(Opener { run: "${EDITOR:-vi} \"$@\"", block: true, orphan: false, desc: "$EDITOR", for_: None, spread: true })
    block-create: Some(Opener { run: "${EDITOR:-vi} \"$@\"", block: true, orphan: false, desc: "$EDITOR", for_: None, spread: true })
    block-rename: Some(Opener { run: "${EDITOR:-vi} \"$@\"", block: true, orphan: false, desc: "$EDITOR", for_: None, spread: true })

Multiplexers
    TMUX               : false
    tmux version       : tmux 3.5a
    tmux build flags   : enable-sixel=Unknown
    ZELLIJ_SESSION_NAME: None
    Zellij version     : 0.41.2

Dependencies
    file          : 5.46
    ueberzugpp    : 2.9.6
    ffmpeg/ffprobe: ffmpeg version N-117845-g67c2f80d2c Copyright (c) 2000-2024 the FFmpeg developers / ffprobe version N-117845-g67c2f80d2c Copyright (c) 2007-2024 the FFmpeg developers
    pdftoppm      : 25.01.0
    magick        : 7.1.1-43
    fzf           : 0.57.0
    fd/fdfind     : 10.2.0 / No such file or directory (os error 2)
    rg            : 14.1.1
    chafa         : 1.14.5
    zoxide        : 0.9.6
    7zz/7z        : No such file or directory (os error 2) / 24.09
    jq            : 1.7.1

Clipboard
    wl-copy/paste: No such file or directory (os error 2) / No such file or directory (os error 2)
    xclip        : 0.13
    xsel         : 1.2.1

Please describe the problem you're trying to solve

I want to make a plugin where I call a custom shell script and I want to display the output in real time like I run it from the shell.
(basicly a wrapper around ffmpeg that handles single or multiple files and displays a progress bar of each file and the total progress)

I tried multiple ways. i.e. using io.open / os.execute ("sh -c '<some script> arg1 arg2 ... argx'")
The script gets executed, but I cant find a way to get the output.
Am I missing a more obvious method?

This is very straight forward using lf and it holds me back to transit completely to yazi...
(

cmd ff ${{
...
<the_script>
...
}}

)

Would you be willing to contribute this feature?

  • Yes, I'll give it a shot

Describe the solution you'd like

A lua function that starts and displays a shell with a given command

Additional context

No response

Checklist

  • I have searched the existing issues/discussions
  • The latest nightly build doesn't already have this feature
@raymondsvendsen raymondsvendsen added the feature New feature request label Feb 5, 2025
@sxyazi
Copy link
Owner

sxyazi commented Feb 6, 2025

Does the shell command work for you?

[[manager.prepend_keymap]]
on  = [ "f", "f" ]
run = """
shell --block '
  <the_script>
'
"""

@raymondsvendsen
Copy link
Author

That works wonderfully!

Sorry to bother you more, but if you have time maybe you can tell me how I can achieve the same from lua too? If I want user-input, confirmation etc, I would think that is where I should put it...?
I tried things like:

 ya.shell("<scriptname>")
 ya.shell("sh -c <scriptname>")
os.execute(...)
io.popen(...)

I managed to execute the script, but not display output while it run. How would I do that in the lua?

The absolute best would be if I could run it in the background and open the progress from the task-window and look at the output(progressbar and such), but that is just extra. A blocking shell window is more than good enough really.

Again thank you for being so helpful!

@sxyazi
Copy link
Owner

sxyazi commented Feb 7, 2025

I'm not quite sure I understand what you mean.

If you want it to run in the background, just remove --block.

If you want to emit a shell command in the plugin, you can do

ya.manager_emit("shell", { block = true, "<the_script>" })

Doc of ya.manager_emit(): https://yazi-rs.github.io/docs/plugins/utils/#ya.manager_emit

Although, I don't really see why you would need a plugin for this.

@raymondsvendsen
Copy link
Author

Hello.
ya.manager_emit("shell", { block = true, "<the_script>" })
Works perfectly. This displays the progressbar too.

Ill try explain why I (think I) need it in plugin again..
Basicly I want to prompt user and add extra parameters to the script...
script <file/dir> <speed> <bitrate>
I want to prompt for speed and bitrate in this example.

Thanks again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature request
Projects
None yet
Development

No branches or pull requests

2 participants