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

Autocomplete for aliases that shadow a different name #6002

Open
farao opened this issue Jul 23, 2019 · 10 comments
Open

Autocomplete for aliases that shadow a different name #6002

farao opened this issue Jul 23, 2019 · 10 comments

Comments

@farao
Copy link

farao commented Jul 23, 2019

It would be really nice to have autocomplete also when using aliases, e.g. when typing git status<tab> I get autocomplete, but when I have an alias gs for git status, I don't. Or is there already a way to achieve this?

I'm currently running fish 3.0.2.

@zanchey
Copy link
Member

zanchey commented Jul 23, 2019

Aliases should set the --wraps option to the function they create. How have you created your aliases? If you used alias gs="git show"; funcsave gs a long time ago, you might need to recreate them.

@farao
Copy link
Author

farao commented Jul 23, 2019

Oh, sorry, I just realized that the issue is a different: For two aliases, I had already existing programs in my PATH. So if there already exists a program with that name that the alias overwrites, then it tries to do the autocomplete for the original program and not for the alias.
E.g. I have an alias that is: alias go="xdg-open" BUT it uses the autocomplete pattern for the Go compiler ("/usr/bin/go") instead of the one of xdg-open - even though when executing go <file> xdg-open is used (as expected).

@faho
Copy link
Member

faho commented Jul 25, 2019

E.g. I have an alias that is: alias go="xdg-open"

I can't recommend doing that. Names are quite important in a shell, and overriding them for the sake of saving a few characters (instead of e.g. open, which we happen to set up by default) isn't worth it.

Anyway, what happens here is that the alias sets up "wrapping" completions in the function (like function go --wraps xdg-open), but still autoloads the completion file given by the original name.

Typically, this is what you want. E.g. if you set up dnf as a wrapper for yum, you still want the dnf completions to be read as well.

Fixing this would require some sort of flag to disable the original completions (e.g. function go --only-wraps xdg-open).

Again, I recommend picking a better name.

@faho faho added enhancement and removed question labels Jul 25, 2019
@faho faho added this to the fish-future milestone Jul 25, 2019
@zanchey
Copy link
Member

zanchey commented Jul 26, 2019

Typically, this is what you want

I'm not so sure about that - I alias (well, abbreviate actually, but the point still stands) gs to git show because I don't care about Ghostscript - and I certainly don't want its completions.

@farao
Copy link
Author

farao commented Jul 29, 2019

I agree with zanchey, I think you never want the completions of another program than you're executing

@danberindei
Copy link

danberindei commented Mar 12, 2020

I'm using fish version 3.0.2 and my aliases are not created with --wraps:

> alias gco "git checkout"
> functions gco
# Defined in - @ line 1
function gco --description 'alias gco git checkout'
	git checkout $argv;
end

I get proper autocomplete if I define the function manually to add -w 'git checkout'.

@faho
Copy link
Member

faho commented Mar 12, 2020

@danberindei Note that fish 3.0.2 didn't show "--wraps" definitions for functions, but it should be defined since 973533e.

If it isn't, the most likely issue is that you've overridden the "alias" function. Check functions --details alias to confirm where it is defined.

@danberindei
Copy link

@faho thanks, I see now that I did not get autocompletions because of #1625 (comment)

@faho faho changed the title Autocomplete for aliases Autocomplete for aliases that shadow a different name Sep 27, 2020
@kaleb
Copy link

kaleb commented Mar 3, 2021

Oh, sorry, I just realized that the issue is a different: For two aliases, I had already existing programs in my PATH. So if there already exists a program with that name that the alias overwrites, then it tries to do the autocomplete for the original program and not for the alias.
E.g. I have an alias that is: alias go="xdg-open" BUT it uses the autocomplete pattern for the Go compiler ("/usr/bin/go") instead of the one of xdg-open - even though when executing go <file> xdg-open is used (as expected).

Perhaps an abbreviation would be better for this scenario using abbr.

@croissong
Copy link

croissong commented Feb 9, 2024

I think you never want the completions of another program than you're executing

I agree with this as well. I have various aliases set for things like

  • ls = eza
  • find = fd
  • cat = bat

and I would assume these are quite common. And I feel like abbreviations are not a good solution for these type of commands either.
Although I am currently debating - coming from zsh - whether to get rid of these renames altogether, given the fact that they can't be escaped as easily as in zsh (#5076)...

Fixing this would require some sort of flag to disable the original completions (e.g. function go --only-wraps xdg-open).

This does sound like a good solution to me tho!

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

No branches or pull requests

6 participants