0

I know, I know, I shouldn't be using TCSH. But I must and so here we are. I'm trying to understand tcsh's complete command for tab completion, and finding it hard to make sense of the documentation page.

In particular, I'm not sure when exactly to use the options p/ c/ and n/ in a complete command. For example, what's the practical difference between the following completion commands?

1. complete test 'c/*/(apple ball)/'
2. complete test 'C/*/(apple ball)/'
3. complete test 'p/*/(apple ball)/'
4. complete test 'n/*/(apple ball)/'
5. complete test 'N/*/(apple ball)/'

The documentation has this to say about the c, p and n pattern:

c

Current-word completion. pattern is a glob-pattern which must match the beginning of the current word on the command line. pattern is ignored when completing the current word.

C

Like c, but includes pattern when completing the current word.

n

Next-word completion. pattern is a glob-pattern which must match the beginning of the previous word on the command line.

N

Like n, but must match the beginning of the word two before the current word.

p

Position-dependent completion. pattern is a numeric range, with the same syntax used to index shell variables, which must include the current word.

So it seems clear enough. But when I run the five above commands, all of them seem to work the same way except for the first one. When I type:

> test <TAB>
apple ball
> test ap<TAB>
apple ball
> test appl<TAB>
apple ball

No matter what I do, it never completes a word, just flashes up the options.

When I use either C, p, n or N however, I get exactly the same results:

> test <TAB>
apple ball
> test ap<TAB>
> test apple
> test apple <TAB>
apple ball
> test apple b<TAB>
> test apple ball

In other words, the shell always shows both of the options I gave it, and always completes the word from a substring. Given that N, for example, only seems to complete the previous previous word, I would expect typing test a<TAB> to do nothing, because it has no previous previous word to complete. But no, it works fine.

So I clearly haven't understood these options properly, even after reading the docs several times. Could someone help me to break down what the difference is between the different types of completion? When might you use one type over another?

Your Answer

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

Browse other questions tagged or ask your own question.