Open esampaio opened 11 years ago
When you type sub mage foo
and hit Tab, you're running the command sub-mage --complete foo
. You can check the value of "$2"
inside your completion conditional and output a different set of completions there.
We should probably have this as a documented example in the README :)
Great, thanks @sstephenson =] And +1 on adding this to the README
I attempted that, and it still didn't work, I don't want to be a bother here, but is it possible to do this? Here is my code:
# Provide sub completions
if [ "$1" = "--complete" ]; then
if [ "$2" = "foo" ] || [ "$2" = "bar" ]; then
{ echo baz; echo bla; } | sort | uniq
else
{ echo foo; echo bar; } | sort | uniq
fi
exit;
fi
I even tried adding:
echo $#
But it always shows 1
no matter how many parameters before the <tab>
Thanks in advance, again.
Confirmed. Seems like params beyond the first are not being passed to the sub-commands during auto-complete. Verified by dumping:
echo "Params: $1 $2 $3" >&2
in the first line of my auto-complete conditional and then trying it to do auto-complete with multiple args:
sub command <TAB>
sub command arg1 <TAB>
sub command arg1 arg2 <TAB>
The params only ever contain --complete
.
Yep, can confirm also.
First thanks a lot for this, besides being a well thought out framework, it gives us that little push to organize our scripts and share them with the team.
Now for my issue, I'm struggling with the autocompletion, I can make it work for the first level like:
But I cant make it work on the second level, this is what happens:
When I expected:
I've organised the files like:
And put the
--complete
like this:Thanks in advance for any help