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

any ssh or scp TAB leads to "complete: maximum recursion depth reached" infloop #7389

Closed
ilohmar opened this issue Oct 9, 2020 · 10 comments
Closed
Labels
bug Something that's not working as intended
Milestone

Comments

@ilohmar
Copy link

ilohmar commented Oct 9, 2020

Please tell us which fish version you are using by executing the following:
fish, version 3.1.2

Please tell us which operating system and terminal you are using. The output of uname -a and echo $TERM may be helpful in this regard although other commands might be relevant in your specific situation.
Linux t430il 5.8.0-2-amd64 #1 SMP Debian 5.8.10-1 (2020-09-19) x86_64 GNU/Linux
st-256color

The issue does not occur in the no-customizations setup, where I do not get any TAB completions at all. I have an

alias ssh="env TERM=screen command ssh"

but removing it (functions -e ssh) does not change the situation. I also tried to mv my ssh config out of the way, also without any effect. That's when I was a bit stumped --- what could go wrong here?

@krobelus krobelus added the bug Something that's not working as intended label Oct 9, 2020
@faho
Copy link
Member

faho commented Oct 9, 2020

See also #6899

@ilohmar
Copy link
Author

ilohmar commented Oct 9, 2020

That's why I checked if removing the alias function makes a difference -- it did not.

@faho
Copy link
Member

faho commented Oct 9, 2020

Please remove it in a new shell

@faho
Copy link
Member

faho commented Oct 9, 2020

As in start a shell that never has it. Remove it from the config.

@ilohmar
Copy link
Author

ilohmar commented Oct 9, 2020

That works, indeed, thank you! And now I have two Q.s :)

  1. What is "left" of the alias function for ssh when I do functions -e ssh (which was meant to get rid of it)?

  2. What is wrong with alias ssh="env TERM=screen command ssh" that lets the completion fail?

If this is doc.d, I would appreciate pointers!

@faho
Copy link
Member

faho commented Oct 9, 2020

Alias defines completions. In this case it tells fish to complete your alias like the command it calls - env. Only the env completions say to complete like the subcommand, ssh. Which is also the name of your alias. Which results in an infinite loop.

The completions remain defined even if the function is erased.

What you can do is either

-make it an actual function directly

function ssh
    TERM=screen command ssh $argv
end

(no need for the env in fish 3.1)

or to call it something else.

@ilohmar
Copy link
Author

ilohmar commented Oct 9, 2020

Alias defines completions.

I did not consider that, but it makes a lot of sense. Thanks for the explanation.

@ilohmar ilohmar closed this as completed Oct 9, 2020
@faho faho reopened this Oct 9, 2020
@faho
Copy link
Member

faho commented Oct 9, 2020

Reopening this one because it shouldn't fail like that.

@krobelus krobelus added this to the fish 3.2.0 milestone Oct 9, 2020
krobelus added a commit that referenced this issue Oct 10, 2020
These aliases seem to be common, see #7389 and others.  This prevents
recursion on that example, so `alias ssh "env TERM=screen ssh"` will just
have the same completions as ssh.

Checking the last token is a heuristic which hopefully works for most
cases. Users are encouraged to use functions instead of aliases.
@krobelus
Copy link
Contributor

Okay, the completion repeated ad infinitum because the env completions called subcommand completions multiple times, instead of just once.
Fixed that, and modified alias to not define those recursive completions in the first place.

alias ssh "TERM=screen ssh" already worked on master before my fix, but not on 3.1.2.
This seems to be a common pattern in other shells.

alias ssh="env TERM=screen command ssh"

A shell gotcha: command is a shell builtin, but env is an external program. Hence command will not work, and is actually not needed since env can only see external commands anyway.

@ilohmar
Copy link
Author

ilohmar commented Oct 10, 2020

A shell gotcha: command is a shell builtin, but env is an external program.
Hence command will not work, and is actually not needed since env can only see external commands anyway.

Thanks, realized that when writing a temporary workaround function. Thanks for your help and for the fix!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something that's not working as intended
Projects
None yet
Development

No branches or pull requests

3 participants