简体   繁体   中英

tcsh completion: Suffix variables with =

I am working on a make completion in tcsh. The desired completion for new words may be either make-targets or variables.

For example:

complete make 'n/*/(footarget1 bartarget2 FOOVAR1= BARVAR2=)/'

By writing it this way, a new space is suffixed after the completion which is not convenient when trying to set a VAR (have to delete the space).

If I set the suffix to null it will not be convenient when completing a target (should type a space for next arguement).

Is there a way to suffix a space when one of the targets is completed but not suffix anything when a VAR is?

It's simple, as long as all your targets can be separated from Variables by upper/lowercase.

complete make \
'C@B*@(BARVAR2=)@@' \
'C@F*@(FOOVAR1=)@@' \
'C@V*@(VAR1= VAR2=)@@' \
'n@*@(target1 target2 VAR1 VAR2 BARVAR2 FOOVAR1)@'

For completion, only the first (read from top to bottom) rule which fits is used.
If you start with uppercase ' B ', then the first rule hits, completing to BARVAR2= , ommitting the suffix space.
If you start with uppercase ' F ', FOOVAR1= is completed similarly.
' V ' has two options, separated by spaces.
You can add new variables by simply adding them in the parenthesis of their starting character. If you need other starting characters, simply duplicate the line 'C@B*@(BARVAR2=)@@' \\ and replace B* with your character (eg G* ) in the newly generated line.

If your input does not start with these uppercase characters, the last rule applies, completing to target1/target2.
These will be added with suffix space, if the match can be completed without ambiguity.

As a bonus, you could also put these as your first rules:

'c@B*=@(val1)@' \|
'c@F*=@(val2)@'  

If your current word is BARVAR2= , then this rule will give you val1 as completion.
For FOOVAR1= it gives val2 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM