2

Scenario

  1. I like to use a multi-line prompt.
set prompt="${bold}${green}%M${white}:${red}%c5${unbold} \n${white}% "
  1. I quite often copy/paste terminal lines into Windows emails.

Problem

It appears that tcsh does not print a true newline character to the terminal. It seems that it prints enough space characters to cause the line to wrap instead. This causes my paste into Windows email to not put the 2cd line of my prompt on a new line. Instead, I just get a bunch of space characters.

I have these Xresources:

xterm*trimSelection:      true
xterm*highlightSelection: true

This grab makes it easy to see what's going wrong. See how there are newlines in the ls output. But the first line of my prompt is actually just enough spaces to cause a line wrap, but not a newline character. Triple-click (line) selection also makes it clear that my "multiline" prompt is really just a single line with spaces embedded.

Short of forking/recompiling tcsh, does anyone know how to fix this?

Thanks!
--Myles

First line of prompt contains spaces, not newline char

3

tl;dr add this to your ~/.tcshrc or ~/.cshrc:

settc am no

A nasty unintended effect of that will be that long commands that are wrapped through multiple lines will have a newline inserted when selected -- it's up to you to decide which is worse.


If you run tcsh inside script(1), you'll clearly see what it's up to:

$ script -qc tcsh
tcsh% set prompt = "foo\nbar% "
foo
bar% exit
exit
$ cat -v typescript
...
foo^[[80G  ^Mbar% exit^M^M

tcsh will translate a newline inside the prompt into a move to the last column (via the hpa/ch \e[80G escape) followed by two spaces and a carriage return (only tcsh will do that; the real csh won't). You can have a look at the MoveToLine() function in its source code.

For some reason, xterm and other terminal emulators will interpret the move to the last column as if the whole line was filled with spaces, any settings like highlightSelection notwithstanding.

A quick and dirty workaround is to convince tcsh that your terminal has no automatic margins, which is what the settc am no command does.

  • That's some great information mosvy. And I didn't know about the 'script' command, so that's helpful too. Unfortunately you properly characterized the side effect as nasty. That's too nasty for me. I copy/paste long, multi-line commands all day long (the main reason I use a multi-line prompt is to have more columns for the command space). And I must have them as a single line. So now I am considering an enhancement request to the tcsh folks, if there are still any around. I see lots of recent commits, so that's good. Thanks!! – Myles Prather Aug 21 at 22:11
  • Enhancement request submitted here. – Myles Prather Aug 21 at 22:43

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.