kislyuk / argcomplete

Python and tab completion, better together.
https://kislyuk.github.io/argcomplete/
Apache License 2.0
1.39k stars 129 forks source link

`argcomplete` adds entries to `.bash_completion`, even when action is abandoned #457

Closed piotrminkina closed 7 months ago

piotrminkina commented 7 months ago

Hello,

This is what my environment looks like on which I run argcomplete.

$ python --version
Python 3.10.12
$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy

I install argcomplete a user's home directory.

$ which activate-global-python-argcomplete
$ pip install argcomplete==3.1.5
[...]
$ which activate-global-python-argcomplete
/home/argcomplete/.local/bin/activate-global-python-argcomplete
$ cat ~/.bash_completion
cat: /home/argcomplete/.bash_completion: No such file or directory

I run argcomplete to add the appropriate entries to the shell files.

$ activate-global-python-argcomplete --user
[...]
$ cat ~/.bash_completion

# Begin added by argcomplete
source "/home/argcomplete/.local/lib/python3.10/site-packages/argcomplete/bash_completion.d/_python-argcomplete"
# End added by argcomplete

So far everything is fine, but the problem occurs when I restart argcomplete. I am then asked if the action should continue. I answer in the negative, so the shell files should not be changed, yet argcomplete still does it.

$ activate-global-python-argcomplete --user
[...]
OK to proceed? [y/n] n
Adding shellcode to /home/argcomplete/.zshenv...
Added.
[...]
OK to proceed? [y/n] n
Adding shellcode to /home/argcomplete/.bash_completion...
Added.
[...]
$ cat ~/.bash_completion

# Begin added by argcomplete
source "/home/argcomplete/.local/lib/python3.10/site-packages/argcomplete/bash_completion.d/_python-argcomplete"
# End added by argcomplete

# Begin added by argcomplete
source "/home/argcomplete/.local/lib/python3.10/site-packages/argcomplete/bash_completion.d/_python-argcomplete"
# End added by argcomplete

Since I am reporting this problem, I would appreciate it if you would implement a parameter that allows you to make a decision already at the command line stage, which would help me a lot in my automation scripts. Some kind of parameter like --default-no and --default-yes.

Thanks :)

Regards Piotr Minkina

kislyuk commented 7 months ago

Thank you for reporting. Fixed the behavior so the action does not run if a "no" answer is received. Released in v3.1.6.

Appending to rc files is only meant to be done in interactive mode, so I'm going to pass on the non-interactive parameters for now.