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

[django] Django bash-completion breaks on blesh #395

Open
REmerald opened this issue Jan 27, 2024 · 5 comments
Open

[django] Django bash-completion breaks on blesh #395

REmerald opened this issue Jan 27, 2024 · 5 comments

Comments

@REmerald
Copy link

GNU bash, version 5.2.26(1)-release (x86_64-pc-linux-gnu) [Garuda Linux]
ble.sh, version 0.4.0-devel4+29cd8f10 (noarch) [git 2.43.0, GNU Make 4.4.1, GNU Awk 5.3.0, API 4.0, PMA Avon 8-g1, (GNU MPFR 4.2.1, GNU MP 6.3.0)]
bash-completion, version 2.11 (hash:2d02f73e803daa87a06e94e33b2a7b3e672a2c0c, 76338 bytes) (noarch)
locale: LANG=en_US.UTF-8 LC_ADDRESS=en_US.UTF-8 LC_IDENTIFICATION=en_US.UTF-8 LC_MEASUREMENT=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 LC_NAME=en_US.UTF-8 LC_NUMERIC=en_US.UTF-8 LC_PAPER=en_US.UTF-8 LC_TELEPHONE=en_US.UTF-8 LC_TIME=en_US.UTF-8
terminal: TERM=xterm-kitty wcwidth=15.0-west/15.1-2+ri, kitty:0 (1;4000;29)

The issue is caused by blesh trying to complete arguments to file manage.py created by django-admin startproject ah_project .:

(ah_env) [remorin@chuwawa:1 antih]$ ./manage.py mbash: manage.py: command not found
mibash: manage.py: command not found
bash: manage.py: command not found
bash: manage.py: command not found
bash: manage.py: command not found
migbash: manage.py: command not found
bash: manage.py: command not found
bash: manage.py: command not found
bash: manage.py: command not found
migrbash: manage.py: command not found
bash: manage.py: command not found
bash: manage.py: command not found
bash: manage.py: command not found
migrabash: manage.py: command not found
bash: manage.py: command not found
bash: manage.py: command not found
bash: manage.py: command not found
migratbash: manage.py: command not found
bash: manage.py: command not found
bash: manage.py: command not found
bash: manage.py: command not found
migratebash: manage.py: command not found
bash: manage.py: command not found
bash: manage.py: command not found
bash: manage.py: command not found
migrate #bash: manage.py: command not found
# bruhhhh

Same without autocompletion on TAB:

(ah_env) [remorin@chuwawa:1 antih]$ ./manage.py migrbash: manage.py: command not found
bash: manage.py: command not found
bash: manage.py: command not found
bash: manage.py: command not found

Without blesh, completion works as expected: ./manage.py mig -> ./manage.py migrate , ./manage.py m ->

(ah_env) [remorin@chuwawa:1 antih]$ ./manage.py m
makemessages    makemigrations  migrate

Removing only /usr/share/bash-completion/completions/manage.py "fixes" in on both blesh and pure bash, completion just reverts to file completion. FYI, this is just a symlink to /usr/share/bash-completion/completions/django-admin.py

[remorin@chuwawa:0 ~]$ ll /usr/share/bash-completion/completions/manage.py
lrwxrwxrwx 1 root root 15 Nov  7 23:24 /usr/share/bash-completion/completions/manage.py -> django-admin.py

Here's the files (renamed because of github): manage.py.txt django-admin.py.txt

@akinomyoga
Copy link
Owner

Thank you for the detailed report, which was sufficient to reproduce the problem.

I added an adjustment in commit 0cf0383. I haven't tested with the actual Django command, so could you update ble.sh by running ble-update and see if the problem is fixed?

Backgrounds

Actually, the original behavior was a part of the intentional behavior change by ble.sh to improve the completion, but I haven't assumed cases where the completion that applies to the relative-path commands (such as ./manage.py) is registered with the basename of the command (as complete -F _django_completion manage.py as in the provided django-admin.py.txt). I decided to adjust the behavior of ble.sh's programmable completion.

For more context, the programmable completion of plain Bash doesn't support the cases where the command names are quoted, such as './manage.py' m[TAB] or "./manage.py" m[TAB] or \./manage.py m[TAB]. The last one is partially covered by the bash-completion project, but it still fails with the Django completion. To cover such a situation, ble.sh tried to virtually reconstruct the command line as manage.py m[TAB] (where the command name is replaced by the name registered to complete) and then called the completion functions.

For the provided case of Django, even though the actual command seems to be called by ./manage.py, the registered name is manage.py. This made ble.sh reconstruct the command line as manage.py m[TAB] but not ./manage.py m[TAB]. Then, the completion for Django seems to try to execute the command name in the command line, which resulted in the execution attempt of non-existent manage.py. I adjusted ble.sh to reconstruct the command line using the value of the specified command name while removing the quotes if possible.

@REmerald
Copy link
Author

@akinomyoga Updated, works now (the behavior now is the same as pure bash). Thanks.
Works with both ./manage.py m[TAB], Documents/.../manage.py m[TAB] and /home/remorin/Documents/.../manage.py m[TAB]. (Haven't actually tested the last one before the fix. Maybe it would have worked?)
Let me know if there're more situations like these 3 I should test.

@akinomyoga
Copy link
Owner

(Haven't actually tested the last one before the fix. Maybe it would have worked?)

It shouldn't have worked before either.

Let me know if there're more situations like these 3 I should test.

I think these are sufficient. Thank you!

@akinomyoga akinomyoga changed the title Django bash-completion breaks on blesh [django] Django bash-completion breaks on blesh Jan 31, 2024
@REmerald
Copy link
Author

@akinomyoga the issue is still present if I try to execute the file indirectly (as an argument to the interpreter):

[remorin@chuwawa:0 antih]$ ah_env/bin/python manage.py mbash: manage.py: command not found
mibash: manage.py: command not found
bash: manage.py: command not found
bash: manage.py: command not found
bash: manage.py: command not found
migbash: manage.py: command not found
bash: manage.py: command not found
bash: manage.py: command not found
bash: manage.py: command not found
ah_env/bin/python manage.py mig
[remorin@chuwawa:0 antih]$ python manage.py mbash: manage.py: command not found
mibash: manage.py: command not found
bash: manage.py: command not found
bash: manage.py: command not found
bash: manage.py: command not found
python manage.py mi
[remorin@chuwawa:0 antih]$

@REmerald REmerald reopened this Feb 10, 2024
@akinomyoga
Copy link
Owner

Sorry for the delay. Now some issues are stacking, so it will still take some time. Hopefully, I can look at this next week.

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

2 participants