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

Next Tab macros? #1318

Closed
1 task
gotbletu opened this issue Jul 20, 2024 · 4 comments
Closed
1 task

Next Tab macros? #1318

gotbletu opened this issue Jul 20, 2024 · 4 comments
Labels
feature New feature request

Comments

@gotbletu
Copy link

Please describe the problem you're trying to solve

is there a way to execute a command and get the next tab path using a variable?

this is possible in ranger, theres a thing called macros so im not sure if it exist on yazi yet

   Macros can be used in commands to abbreviate things.
    %f   the highlighted file
    %d   the path of the current directory
    %s   the selected files in the current directory
    %t   all tagged files in the current directory
    %c   the full paths of the currently copied/cut files
    %p   the full paths of selected files

   The  macros  %f, %d, %p, and %s also have upper case variants,
   %F, %D, %P, and %S, which refer to the next tab. 
   To refer to specific tabs, add a number in between.  (%7s = selection of the seventh tab.)

This was some of the ranger commands/binding i was using for example

map rX   shell atool -e -X %D %s
map cp   shell cp -n -- %s %D
map mv   shell mv -n -- %s %D
map ry  shell rsync --update -r %s %D

Would you be willing to contribute this feature?

  • Yes, I'll give it a shot

Describe the solution you'd like

add some of those ranger macros ideas so we all can use it in our custom shell commands keybindings.

e.g i want to extract a zip file (current tab) into the next tab using just a keybinding.

or any other commands really like rsync, cp, mv ...etc

Additional context

No response

@gotbletu gotbletu added the feature New feature request label Jul 20, 2024
@sxyazi
Copy link
Owner

sxyazi commented Jul 20, 2024

In the current tab, Yazi has a set of equivalents like $0 for %c, $PWD for %d, $@ and $* for %p. For %f and %s, you can get them using basename, like $(basename "$0"). I'm not sure what %t means in the context of "tagged files"

As for referencing paths across tabs, it’s not directly supported right now, but you can achieve it through the plugin system. In your plugin, you can access file data from all tabs via cx.tabs. You might have something like this:

-- ~/.config/yazi/plugins/my-shell.yazi/init.lua
local function quote(tab)
  return tab and ya.quote(tostring(tab.current.hovered.url)) or ""
end
return {
  entry = function(_, args)
    ya.manager_emit("shell", {
      block = true,
      confirm = true,
      args[1] .. " " .. quote(cx.tabs[1]) .. " " .. quote(cx.tabs[2]),
    })
  end,
}

And the keybindings:

{ on = "D", run = 'plugin my-shell --sync --args=diff', desc = "Diff tab1 and tab2" },
{ on = "E", run = 'plugin my-shell --sync --args=echo', desc = "Echo tab1 and tab2" },

Yazi now uses the native $ syntax from the shell and relies on the shell to expand them instead of implementing its own interpreter and I also want to avoid introducing a different % syntax.

If we were to support it directly, we'd need to figure out a way to make both compatible.

@sxyazi sxyazi added the waiting on op Waiting for more information from the original poster label Jul 20, 2024
@gotbletu
Copy link
Author

Thanks for the reply, hopefully there is a better solution in the future.

@github-actions github-actions bot removed the waiting on op Waiting for more information from the original poster label Jul 22, 2024
@sxyazi sxyazi mentioned this issue Sep 2, 2024
55 tasks
@sxyazi
Copy link
Owner

sxyazi commented Sep 2, 2024

Tracked by #51

@sxyazi sxyazi closed this as completed Sep 2, 2024
Copy link

github-actions bot commented Oct 3, 2024

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 Oct 3, 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

No branches or pull requests

2 participants