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

Alias shell support #1206

Closed
1 task done
AnirudhG07 opened this issue Jun 25, 2024 · 8 comments
Closed
1 task done

Alias shell support #1206

AnirudhG07 opened this issue Jun 25, 2024 · 8 comments
Labels
feature New feature request

Comments

@AnirudhG07
Copy link
Contributor

Please describe the problem you're trying to solve

I have a ton of aliases, like for example instead of lazygit, I am used to typing lg. So when I press : for shell, and type lazygit, it works fine but not with lg.
Similarly for other aliases too.

Would you be willing to contribute this feature?

  • Yes, I'll give it a shot

Describe the solution you'd like

If from my ~/.zshrc (or bashrc, etc.) aliases can be ran through a flag --alias then it would be great. This would add on the functionalities.

Additional context

Also I don't know how to write lua/rust but if someone can help me with how to do it. I am willing to work on this.

@AnirudhG07 AnirudhG07 added the feature New feature request label Jun 25, 2024
@sxyazi
Copy link
Owner

sxyazi commented Jun 25, 2024

Yazi uses sh by default because it's available on all platforms, on most Linux systems, sh points to bash, so if your aliases are defined in bashrc, it should work fine.

For zsh, a potential solution is to allow users to set the default shell, but this would require us to adapt to different shells (zsh, fish, nushell), which would be a complex task due to needing to consider the specific behaviors and all edge cases of each shell. I don't have plan to support this, but I'm open to reviewing and accepting PRs for it.

Another solution is to define those aliases in Yazi, like:

{ on = [ ":", "l", "g" ], run = "shell lazygit --block --confirm" }

Or, if you just want to use zsh, you can achieve it with a simple plugin (save it as ~/.config/yazi/plugins/zsh.yazi/init.lua):

return {
  entry = function()
    local value, event = ya.input {
      title = "Zsh shell:",
      position = { "top-center", y = 3, w = 40 },
    }
    if event == 1 then
      ya.manager_emit("shell", {
        "zsh -ic " .. ya.quote(value .. "; exit", true),
        block = true,
        confirm = true,
      })
    end
  end,
}

Then bind it in your keymap.toml:

{ on = [ ":" ], run = "plugin zsh" }

@sxyazi sxyazi closed this as completed Jun 25, 2024
@AnirudhG07
Copy link
Contributor Author

That did not work.
image

This is how it looks like. I tried changing the keymap directly where it originally as well as adding separately like-

[[manager.prepend_keymap]]
on = [":"]
run = "plugin zsh"
desc = "Run zsh commands"

Although if I do plugin --sync zsh, it didnt show the error. but didnt work either.

@sxyazi
Copy link
Owner

sxyazi commented Jun 25, 2024

I've updated the code, try it again. This is how it works on my side:

screenshot-000830.mp4

@AnirudhG07
Copy link
Contributor Author

I donno why it is not working for me :( . Is their any thing I can send details on so that it can be debugged? It looks ideal at your end.

@sxyazi
Copy link
Owner

sxyazi commented Jun 25, 2024

This plugin essentially does:

sh -c 'zsh -ic "your-alias-here; exit"'

so you can run it directly in your shell and see what happens.

@AnirudhG07
Copy link
Contributor Author

AnirudhG07 commented Jun 25, 2024

That worked perfectly. it opened lazygit nicely.

oh wait. I see what might be the problem. I have setup few commands to run when my zsh opens like taskwarrior. Thats why it didnt open directly. Although lazygit takes over the whole screen so it should technically work in yazi as well. What do you think? ( This is a bit personal customisation going on here)

Ill report back to you the results after I remove them.
Results: Didnt work still. weird

@AnirudhG07
Copy link
Contributor Author

It works fine even with and without having the extra text and commands.

Copy link

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 Jul 30, 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