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

Autocomplete on 3rd level argument? #7

Open
esampaio opened this issue Oct 3, 2012 · 6 comments · Fixed by JudStephenson-drizly/sub#1 · May be fixed by #35 or #37
Open

Autocomplete on 3rd level argument? #7

esampaio opened this issue Oct 3, 2012 · 6 comments · Fixed by JudStephenson-drizly/sub#1 · May be fixed by #35 or #37

Comments

@esampaio
Copy link

esampaio commented Oct 3, 2012

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:

❯ sub mage <tab>
foo        bar 

But I cant make it work on the second level, this is what happens:

❯ sub mage foo <tab>
foo        bar 

When I expected:

❯ sub mage foo <tab>
baz        fubar 

I've organised the files like:

libexec/sub-mage
libexec/sub-mage-foo
libexec/sub-mage-bar
libexec/sub-mage-foo-baz
libexec/sub-mage-foo-fubar

And put the --complete like this:

# Provide sub completions
if [ "$1" = "--complete" ]; then
    { echo foo; echo bar; } | sort | uniq
    exit;
fi

Thanks in advance for any help

@sstephenson
Copy link

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.

@qrush
Copy link
Owner

qrush commented Oct 3, 2012

We should probably have this as a documented example in the README :)

@esampaio
Copy link
Author

esampaio commented Oct 3, 2012

Great, thanks @sstephenson =]
And +1 on adding this to the README

@esampaio
Copy link
Author

esampaio commented Oct 3, 2012

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.

@bradical
Copy link

bradical commented Nov 9, 2012

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.

@capotej
Copy link

capotej commented Nov 28, 2012

Yep, can confirm also.

@qrush qrush reopened this Dec 7, 2012
@dhinus dhinus linked a pull request Jan 16, 2013 that will close this issue
jeffreyroberts added a commit to jeffreyroberts/sub that referenced this issue Apr 23, 2013
@jeffreyroberts jeffreyroberts linked a pull request Apr 23, 2013 that will close this issue
cofyc pushed a commit to cofyc/sub that referenced this issue Apr 29, 2014
Fixes qrush#7
(if using bash)

When bash-completion is invoked, all arguments are now
forwarded to the command, e.g.

sub command arg1 arg2 <tab>

now triggers:

sub --complete command arg1 arg2

instead of just:

sub --complete command
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants