3

Say I have a script foo which can be called as:

foo git clone http://example.com

or as:

foo print 12

etc.

How can I make a compdef that delegates to $argv[0] here to allow it to handle completion?

tshepang
  • 12,111
  • 21
  • 91
  • 136
Julian
  • 3,375
  • 16
  • 27

1 Answers1

4

You can redispatch into the normal completion system by calling the _normal function, but first you need to modify some of the state so that it will ignore your program name and possibly its arguments. A very simple version of this can be done with:

#compdef foo
shift words
(( CURRENT-- ))
_normal

If you need to get more complicated that that (which is likely), you can take a look at the completion definitions for other commands that call _normal, such as the completions for env, sudo, or fakeroot.

qqx
  • 18,947
  • 4
  • 64
  • 68