cobra
cobra copied to clipboard
Allow setting prefix to remove before completing directories?
Hello, I'm trying to write custom completions for skopeo, and I ran into something that I don't know if it's possible to do using the builtin cobra completions.
I'm trying to make this complete directories:
skopeo copy dir:<TAB>
I tried returning nil, cobra.ShellCompDirectiveFilterDirs | cobra.ShellCompDirectiveNoFileComp
, but this doesn't complete anything. It seems to be because _filedir -d
looks at $cur
when completing (when it eventually calls compgen here), and since cur is dir:
it doesn't find any completions. I manually edited the completion file and it did manage to complete directories like I wanted:
cur=${cur#"dir:"}
_filedir -d
Is there some way to solve this issue with cobra? The PR I created for skopeo: https://github.com/containers/skopeo/pull/2524
I only tested this with bash
Bash version: 5.1.16(1)-release