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

Bash Completion for python based commands (Ansible) #31

Closed
Ergamon opened this issue Dec 9, 2021 · 8 comments
Closed

Bash Completion for python based commands (Ansible) #31

Ergamon opened this issue Dec 9, 2021 · 8 comments
Assignees
Labels
bug Something isn't working

Comments

@Ergamon
Copy link

Ergamon commented Dec 9, 2021

Describe the bug
The argument completer does not find the correct completion for python based commands.

To Reproduce
Steps to reproduce the behavior:

apt install ansible
apt install python3-argcomplete

Test functionality in wsl, e.g.

ansible-playbook --a
this results in
ansible-playbook --ask

Leave wsl and create the command in PowerShell:
Import-WslCommand ansible-playbook

Expected behavior
Getting the same result in PowerShell, but

ansible-playbook --a
results in
ansible-playbook --a

So nothing happens.

Additional context
The behavior is clear, if I query the following in PowerShell

$global:WslCompletionFunctions

I can see that the value for ansible-playbook is "_minimal".

So basically the problem is in line 126 of WslInterop.psm1:

$global:WslCompletionFunctions[$command] = wsl.exe bash -c ". /usr/share/bash-completion/bash_completion 2> /dev/null; __load_completion $command 2> /dev/null; complete -p $command 2> /dev/null | sed -E 's/^complete.-F ([^ ]+).`$/\1/'"

My bash knowledge is way too low to fix this.

Do you have any idea how to fix this or at least what I can manually set by:

$global:WslCompletionFunctions["ansible-playbook"] = "???"

Thx for your great module, I enjoy it almost every day, but this would improve my work even a little more.

@Ergamon
Copy link
Author

Ergamon commented Dec 9, 2021

Just a quick update, meanwhile I figured out, how to solve the problem manually:

$global:WslCompletionFunctions["ansible-playbook"] = '_python_argcomplete_global "ansible-playbook"'

When I execute this, the tab completion works as expected in PowerShell.

Of course it would be nice, if the module could figure this out by itself, but as said my knowledge about bash is very low. Maybe this helps

@mikebattista mikebattista self-assigned this Jan 25, 2022
@mikebattista
Copy link
Owner

Thanks for filing. I'll take a look.

@mikebattista
Copy link
Owner

I don't seem to get completions within WSL. I tried with both WSL 1 and WSL 2. I installed ansible and python3-argcomplete. Am I missing something else?

@mikebattista mikebattista added the bug Something isn't working label Jan 25, 2022
@Ergamon
Copy link
Author

Ergamon commented Jan 25, 2022

You are almost there. You need ansible and python3-argcomplete.

Then you need to run:

sudo activate-global-python-argcomplete3

@mikebattista
Copy link
Owner

Thanks. I see what's happening here. activate-global-python-argcomplete3 is overriding bash's default completion function rather than assigning a completion function to each command.

I'll need to think through how to potentially handle this.

@mikebattista
Copy link
Owner

Could you try out the latest changes in the master branch? Just overwrite your copy of (gmo WslInterop).Path with the latest version.

You'll need to clear your WslCompletionFunctions cache by running "ri $Env:APPDATA\PowerShell WSL Interop\WslCompletionFunctions" and then restarting PowerShell.

@mikebattista mikebattista reopened this Jan 25, 2022
@Ergamon
Copy link
Author

Ergamon commented Jan 25, 2022

I did a small test and it looks good. A little bit strange to see "-D" in the output of the completion functions, but it works. Personally I would have used a specific variable like WslCompletionLoader, but from a user perspective it works.

(Speaking of variables, maybe it is a good idea to initialize the WslDefaultParameterValues as an emtpy hashtable, if it does not already exist while loading the module. I find it always annoying to check if it exists before I can add a value. It has nothing to do with this topic,.)

@mikebattista
Copy link
Owner

I did a small test and it looks good.

Excellent.

(Speaking of variables, maybe it is a good idea to initialize the WslDefaultParameterValues as an emtpy hashtable, if it does not already exist while loading the module. I find it always annoying to check if it exists before I can add a value. It has nothing to do with this topic,.)

I wanted to keep the global session state clean unless you use a feature, and I'd expect if you're reusing your preferred defaults, you would initialize the hash table in your profile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants