fish-shell / fish-shell/fish-shell
alias should check for `command foo` when generating `--wraps` to prevent recursion
- Dominant language
- Rust
- Stars
- 34.2k
- Forks
- 2.4k
- Avg merge
- 2d 8h
- Merged PRs (30d)
- 13
Description
I got bit by the "error: completion reached maximum recursion depth, possible cycle?" alias issue today. I couldn't find this exact issue reported here, but others have definitely [experienced it](https://unix.stackexchange.com/questions/675018/fish-maximum-recursion-depth-reached-with-tab-complete). Essentially, if you create an alias to override a built-in using `command foo`, the `--wraps` statement gets built in such a way as to confuse completion and causes a `max recursion` issue.
I got it by creating this alias: `alias grep "command grep --color=auto --exclude-dir={.git,.hg,.svn}"`.
The alias.fish function tries to detect recursion, but doesn't specifically look for the `command` keyword.
https://github.com/fish-shell/fish-shell/blob/d50e9ffff35a12b542f41e1bdf1ad5357fba7ead/share/functions/alias.fish#L61-L68
A possible simple solution is to add an additional check: `test $first_two_words != "command $name"`
This is similar to, but not the same as #7389 and #6899.
The workaround is to change the `--wraps` manually after running `funcsave foo`.
Contributor guide
Assessment
This issue has not been assessed yet.