Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

Cheers

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

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

1 Answer 1

up vote 3 down vote accepted

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.

share|improve this answer
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 '11 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 '11 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. –  redstreet Aug 23 '13 at 22:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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