I'm trying to get some efficient auto-completing going here, and have hit upon a bit of a snag.

I've got a command for setting two things at once. The first is a relatively small list, but the second, if not filtered by the first, is unmanageably huge.

What I want to be able to do is pass what's already been typed or auto-completed for the first argument to the second autocomplete command...

complete job 'p/1/`listJobs`/' 'p/2/`listTasks`/'

What I want to be able to do is pass the job that has already been entered for the first argument to the 'listTasks' command.

Any idea how I can do this?


(this is a repost from an old SuperUser.com question of mine that nobody ever answered... The SuperUser question can be found here)

  • Please add a link to the SU question, in case someone eventually answers there. And link back, for the symmetric reason. Dec 10, 2010 at 21:11
  • Sure - edited on both sides...
    – Hugh
    Dec 11, 2010 at 15:18

1 Answer 1


Here's the best option I've been able to find:

complete job 'p/1/`listJobs`/' \
             'p/2/`set cmd = ( $COMMAND_LINE ); listTasks $cmd[$#cmd]`/'

It's relying on a variable called $COMMAND_LINE, which is available on my Ubuntu system, but I'm not sure if it's standard.

command invoked from ... version has additional environment variable set, the variable name is COMMAND_LINE and contains (as its name indicates) contents of the current (already typed in) command line. One can examine and use contents of the COMMAND_LINE variable in her custom script to build more sophisticated completions (see completion for svn(1) included in this package).

Failing that, you would experiment with history expansions such as !! or !#$, but I'm not sure if that will work.

  • 1
    Many thanks! That, I have discovered, is part of tcsh 6.17.00 (comes with Ubuntu 10.4), but not tcsh 6.14.00 (comes with Centos 5.5 and OSX)
    – Hugh
    Feb 16, 2011 at 23:16
  • Oh, and I would actually vote up your answer as well, but I'm unfortunately unable to, as I don't quite have the reputation for that yet...
    – Hugh
    Feb 16, 2011 at 23:17
  • @Hugh You're correct: tcsh-6.14.00 does not set COMMAND_LINE when calling a program within `` for autocomplete. 6.17.00 does.
    – PonyEars
    Aug 23, 2013 at 22:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.