(Crossposted from StackOverflow.com)

This question and the answer teach us how to introduce colour into tcsh prompts.

This webpage explains nicely how to get colour into any output of the echo command:

> echo \\e[1\;30mBLACK\\e[0m
> echo '\e[1;30mBLACK\e[0m'

The word 'BLACK' in the example above is printed with a black (or darkgrey) foreground colour (depending on the overall color scheme).

Now I'd like to introduce this into the [TAB] command autocompletion feature of tcsh. I tried:

complete testcmd 'p/*/`echo '"'"'\e[1;30mf834fef\e[0m'"'"'`/'

And I get:

> testcmd [TAB]
> testcmd ^[\[1\;30mf834fef^[\[0m

Obviously the characters lose their special meaning. Hopefully I just did not get the escaping right. But I tried several other ways. So any help is appreciated.

The real use case is that I've got a command completion that offers three different types of completions and I'd like to visually distinguish the types. Also the alternatives are computed by an external command. That is why I need the completion to use the backticks with an external command, such as echo. I don't care about the details of this command. If you make it work in any way with the tcsh's complete command I'll probably be able to adapt (thinking perl -pe wrappers and such).

The reason why I believe this has to work somehow is that the tcsh itself offers coloured command completion if you e.g. type ls [TAB]. That works correctly in my setup. Also you can use ls -1F inside the autocompletion and the colours that ls outputs are also piped through. An example would be:

complete testcmd 'p/*/`ls -1F`/'

Update: As user mavin points out on stackoverflow, the colourization of ls in this example is indeed not piped through. The colours of ls are lost, but the auto completion can reapply colours according to LS_COLOURS variable based on hints such as the / and * marker endings as added by the ls. This can be verified by doing

complete testcmd 'p/*/`ls --color -1`/'

which fails to provide colour, and only provides garbled output. (Literally pipes through the escape character sequences)

I'm on tcsh version 6.13.00

Any ideas? Pointers?


It does not seem to be possible, the way I'd like it to work. On stackoverflow, user mavin provided this answer which is the one closest to my sought after behaviour.

If you have a better solution without the drawbacks discussed in the various answers and comments, please add your answer here or on stackoverflow.

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.