Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Console] Autocomplete feature is not working when using alias #44461

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

Closed
tarlepp opened this issue Dec 4, 2021 · 9 comments
Closed

[Console] Autocomplete feature is not working when using alias #44461

tarlepp opened this issue Dec 4, 2021 · 9 comments

Comments

@tarlepp
Copy link
Contributor

tarlepp commented Dec 4, 2021

Symfony version(s) affected

5.4.0

Description

If I use bash alias like;

echo 'alias console="/app/bin/console $@"' >> /home/dev/.bashrc

then autocomplete feature doesn't work when I try following;

dev@php-fpm:/app$ console ut [TAB]

but it works as expected when I use it like;

dev@php-fpm:/app$ ./bin/console ut [TAB]

How to reproduce

See the description.

Possible Solution

No response

Additional Context

No response

@tarlepp
Copy link
Contributor Author

tarlepp commented Dec 4, 2021

Also noticed that if I add that /app/bin to PATH env it doesn't work as expected.

@alessandro-podo
Copy link

bin/console se [TAB] works
php bin/console se [TAB] not working

@wouterj
Copy link
Member

wouterj commented Dec 5, 2021

Hi! Thanks for the reports. Unfortunately, both of them are "can't fix" issues. As "application writers", the only thing we can do is provide a completion script to the shell. In the end, it's up to the shell's logic to run our completion script in the correct cases.

In bash, you configure the bash completion utility using the complete command:

complete -F _sf_{{ COMMAND_NAME }} {{ COMMAND_NAME }}

  • _sf_{{ COMMAND_NAME }} is the completion function defined before it (for Symfony apps: _sf_console)
  • {{ COMMAND_NAME }} is the shell program you want to bind this completion to, console in this case

I'm not sure why /app/bin in PATH doesn't work. As for aliases, I'm 90% sure that bash completion doesn't natively support aliases (e.g. Zsh and Fish do support it natively).

The same applies to php bin/console. In this case, the shell completion will try to find a completion function for the php program (and not the bin/console program - this is "just" an argument of the php program). As there is a lot more to the php program than just bin/console, we don't provide a completion script for it.


If there is someone with great bash skills that is aware of a way to make aliases work, please contribute or comment :) Otherwise, I'm afraid all I can do is close this one.

@wouterj wouterj closed this as completed Dec 5, 2021
@tarlepp
Copy link
Contributor Author

tarlepp commented Dec 5, 2021

Imho - we should at least keep this open a bit more - maybe someone who has some insights for this would spot this easier.

@tarlepp
Copy link
Contributor Author

tarlepp commented Dec 5, 2021

Previously I used - https://github.com/bamarni/symfony-console-autocomplete - for this and it worked with PATH and alias solution - maybe there is something that could help with this one.

@wouterj wouterj reopened this Dec 5, 2021
@wouterj
Copy link
Member

wouterj commented Dec 5, 2021

That's interesting. Which install method did you use for the autocomplete functionality?

@tarlepp
Copy link
Contributor Author

tarlepp commented Dec 5, 2021

Just couple of things on my Dockerfile_dev - this is just for development and not used on production;

ENV PATH "$PATH:/home/dev/.composer/vendor/bin:/app/vendor/bin:/app/bin"

RUN composer --no-cache global require bamarni/symfony-console-autocomplete

RUN echo 'eval "$(symfony-autocomplete --shell bash)"' >> /home/dev/.bashrc

or did you mean how I setup that Symfony autocomplete feature in my setup?

@mindaugasvcs
Copy link
Contributor

Are you aware that autocomplete feature is provided by the shell at OS level?

@tarlepp
Copy link
Contributor Author

tarlepp commented Dec 6, 2021

Are you aware that autocomplete feature is provided by the shell at OS level?

Yes, I know that - but when I was using that - https://github.com/bamarni/symfony-console-autocomplete - autocomplete also worked with PATH and alias use, so I think that ./bin/console completion bash is missing something.

GromNaN added a commit that referenced this issue Dec 7, 2021
This PR was merged into the 5.4 branch.

Discussion
----------

[Console] Handle alias in completion script

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #44461
| License       | MIT
| Doc PR        | -

Detect when completion is triggered by an alias and get the underlying command. Tip extracted from [bamarni/symfony-console-autocomplete](https://github.com/bamarni/symfony-console-autocomplete/blob/v1.4.2/resources/bash/default.php#L7-L10).

Works well with such alias:

```console
alias console=bin/console
```

Doesn't work with these aliases (command name is not the 1st part of the alias):

```console
alias console='APP_ENV=test bin/console'
```

When alias has a different name, the name in the completion script must be updated.

Commits
-------

f3c196a Handle alias in completion script
@wouterj wouterj closed this as completed Dec 7, 2021
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

5 participants