tcsh 'complete' question

CTho9305

Elite Member
Jul 26, 2000
9,214
1
81
I have a program that is invoked:
programName string1 -arg1 filex.type1 -arg2 filey.type2
string1 doesn't have to come first: "programName -arg1 filex.type1 string1 -arg2 filey.type2" and "programName -arg1 filex.type1 -arg2 filey.type2 string1" are both legal. How can I set up a tcsh completion to tab complete "arg1", "arg2", and the files? Requiring string1 to come first is acceptable. Requiring string1 to come last is not acceptable. "Use bash|korn|zsh" is not :)

A little more detail:
programName string1 -textfile [complete *.txt] -otherfile [complete *.bin]

edit: I have a second program that works similarly but requires string1 to come last. I think I can handle that one by just ignoring string1 for the "complete" command.
 

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
What parts of the command are always the same? If most of the command stays the same you could write a wrapper script.

Other than that, I'm looking at the doc for the complete built-in now. :p
 

CTho9305

Elite Member
Jul 26, 2000
9,214
1
81
What do you mean "always the same"?

In normal format, I might document it as:
Usage:
$0 <nameToUse> [-textfile <foo.txt>] [-otherfile <bar.bin>]
The three arguments may be passed in any order, but 95% of people choose this order and if tab-completion only supports one ordering, it has to be this one
 

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
You said the string was (basically):
programName -arg1 filex.type1 string1 -arg2 filey.type2

Are filex.type1, string1, and filey.type2 relatively constant? I'm guessing they're different a lot of the times (string1 one day, string 7 the next, string2 the next, etc.). It makes a wrapper script a little more difficult, but do-able.

Still looking at the complete documentation. Silly things keep popping up.
 

CTho9305

Elite Member
Jul 26, 2000
9,214
1
81
string1 is different every time. arg1 is usually specified, and requires a file of type1. arg2 is sometimes specified, and requires a file of type2. A wrapper script introduces problems - there are a large number of existing users who are resistant to change :)
 

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
Minimal testing and doesn't work with the .bin file yet:
complete ./programName 'p/2/(-textfile)/' 'p/3/t:*.txt/' 'C/*.txt/t/' 'p/4/(-otherfile)/' 'p/5/f:*.bin/'

EDIT: This one's a bit prettier:
complete ./xfile 'p/2/(-arg1)/' 'n/-arg1/t:*.txt/' 'C/*.txt/t/' 'p/4/(-arg2)/' 'n/-arg2/f:*.bin/'

Still not sure why the .bin option doesn't just pull out the .bin files...
 

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
Apparently Plain (``text'') files means something different than I thought...

complete ./xfile 'p/2/(-arg1)/' 'n/-arg1/t:*.txt/' 'C/*.txt/t/' 'p/4/(-arg2)/' 'n/-arg2/t:*.bin/'

EDIT: What a silly shell. ;)
 

CTho9305

Elite Member
Jul 26, 2000
9,214
1
81
It hadn't occurred to me to just require p/2 and p/4 for the arguments. I can probably tweak this to meet the rest of my needs. Thanks!