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

Support compopt in completion functions #78

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

NiklasReisser
Copy link

Fixes #77

@sourcery-ai

This comment was marked as resolved.

@skshetry skshetry requested review from casperdcl and removed request for casperdcl June 10, 2022 14:15
@casperdcl casperdcl self-requested a review June 17, 2022 13:42
@casperdcl casperdcl added enhancement New feature or request shell-bash labels Jun 17, 2022
@casperdcl
Copy link
Collaborator

Thanks for this PR @NiklasReisser! Just merged #81, is this still required?

@NiklasReisser
Copy link
Author

Hi @casperdcl ,

I am on holiday without my laptop from work, so I can't test it.
But for my use case, I'd say yes, this is still required.

Here is what I want to do:
I have a bunch of virtual resource paths which look like filesystem paths, but actually aren't.

For example host/class/subclass/name.

Now I want to complete that peacemeal just like a filesystem path.
To make this work I need compopt -o nospace, otherwise readline adds a space after every part of the path.

I'd also be fine with completing the whole path at once, like any other comletion, but in this case the issue is that shtab enables -o filenames globally for all completions. This causes readline to only print the last bit of the path for the completion.
So if I type hos<tab>, and return the full path from my custom completion function, I get name (and only name) as possible completion.

Best regards,

Niklas

@NiklasReisser
Copy link
Author

@casperdcl Can confirm now, I'd still need this for my usecase.

Cheers
Niklas

@NiklasReisser
Copy link
Author

@casperdcl This issue seems to also prevent usage of bash completion builtins like _available_interfaces, which modify COMPREPLY directly.

@casperdcl
Copy link
Collaborator

casperdcl commented Jul 28, 2022

There's some conflicts now though with the main branch.

Also, would making this line configurable be a simpler alternative?

complete -o filenames -F ${root_prefix} ${prog}""").safe_substitute(

@NiklasReisser
Copy link
Author

Hi,

I've resolved the merge conflict.

Unfortunately, I think making the main "complete" configurable would only allow a global setting for all completions for a given program. My approach is more generic.

I admit I don't particularily like it due to the tmpfile. But it is the only approach I can think of without changing the API.
(With a breaking API-Change, the inner, user-defined function could set or extend COMPREPLY, instead of of printing to stdout.)

@omesser
Copy link
Contributor

omesser commented Apr 2, 2023

@0x2b3bfa0 - PTAL - worth resolving conflicts and merging this?

@0x2b3bfa0
Copy link
Member

@omesser, this pull request uses mktemp in a hardly avoidable but barely convenient way; being unable to find solutions that don't involve creting a subshell, I still hesitate to merge it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bash: compopt not supported in custom complete-functions
5 participants