AnirudhG07 / custom-shell.yazi

Set your custom-shell as default shell in yazi!
MIT License
7 stars 3 forks source link

$0 no longer resolves to the hovered file #4

Open kyletruong opened 1 month ago

kyletruong commented 1 month ago

After adding this plugin, the $0 shell variable no longer resolves to the hovered file. It resolves to zsh in my case, which is my custom shell.

AnirudhG07 commented 1 month ago

Can you share what exactly you are giving into the input? I have been meaning to look into this, just didnt do it yet

kyletruong commented 1 month ago

@AnirudhG07 Yes, for example when I run nvim $0 it opens a new file called zsh instead of opening the currently hovered file.

Screenshot 2024-08-12 at 11 03 42 AM Screenshot 2024-08-12 at 11 04 23 AM
AnirudhG07 commented 1 month ago

I see. fine ill work on fixing this issue. If you would like to contribute, you are very welcome to(do inform me, if you are doing it)! It would take a week-ish, since i am bit busy these days. i hope its fine with you

uxfion commented 3 weeks ago

How is the progress? I am also encountering this issue now, unable to parse $@ after using this plugin.

reproduce

echo $@

it will echo the path of two files.


I think the problem lies in sh -c 'zsh -ic "echo $@; exit"', where $@ is not being interpreted correctly.

It may relate to https://github.com/sxyazi/yazi/issues/1524

I don't know how to handle it.

AnirudhG07 commented 3 weeks ago

Yes. zsh or any shell does not interpret $0 as yazi does. I will work on it. I'll have to look into how to get it to work. Give me some more time

uxfion commented 3 weeks ago
local selected_or_hovered = ya.sync(function()
    local tab, paths = cx.active, {}
    for _, u in pairs(tab.selected) do
        paths[#paths + 1] = tostring(u)
    end
    if #paths == 0 and tab.current.hovered then
        paths[1] = tostring(tab.current.hovered.url)
    end
    return paths
end)

return {
  entry = function()
    ya.manager_emit("escape", { visual = true })
    local urls = selected_or_hovered()
    local paths = table.concat(urls, " ")

    local value, event = ya.input {
      title = "Zsh shell:",
      position = { "top-center", y = 3, w = 40 },
    }
    if event == 1 then
      if value:match("%s$@$") then
        value = value:gsub("%s$@$", " " .. paths)
      end
      ya.notify({
        title = "exec",
        content = "zsh -ic " .. ya.quote(value .. "; exit", true),
        -- content = table.concat(urls, " "),
        timeout = 8,
      })

      ya.manager_emit("shell", {
        "zsh -ic " .. ya.quote(value .. "; exit", true),
        block = true,
        confirm = true,
      })
    end
  end,
}

Take a look at this. It might be a bit clumsy, but it works. Forcibly replace $@ with selected_or_hovered. Perhaps this is unacceptable for this repo.

AnirudhG07 commented 3 weeks ago

I was also thinking in similar direction, but this has to carefully applied so that it works properly with pre-added configs. Thanks for the snippet though, might come in handy.

sxyazi commented 3 weeks ago

I think you can just string.format('zsh -ic %s "$0" "$@"', ya.quote(value .. '; exit', true))