(tcsh) postcmd alias for xterm titlebar breaks less texteditor (tcsh) postcmd alias for xterm titlebar breaks less texteditor unix unix

(tcsh) postcmd alias for xterm titlebar breaks less texteditor


According to this link, the problem is only existant on Red Hat machines only.

From their site:

The "less" command

When I try to use the less command, instead of seeing the contents of a file I see messages that I usually see only when I log in. How do I fix this?

If the .cshrc, .profile, or any other shell start-up file in your home directory prints any text, less will display that text instead of your file.To get rid of this behavior, test to see if you can write to standard output before you actually print anything. For example, assume you're using tcsh shell, and you've put the following statements in your .cshrc file:

echo ".cshrc here"echo "I am logged on to machine $hostname"

Replace this with:

 # "-t 1" is true only if standard output is enabled; # if not, then don't write any messages. if ( -t 1 ) then                                                  echo ".cshrc here"    echo "I am logged on to machine $hostname" endif

An equivalent test in an sh-style shell:

 if [ -t 1 ]; then    echo ".profile here"    echo "I am logged on to machine $hostname" fi

A FAQ within a FAQ: Why does less do this?

In RedHat Linux, less has a facility to display other types of files in addition to plain text. For example, if you type:

less ${NevisAppBase}/src/archive-tar/gcc-2.95.2.tar.gz

you will see a list of the compressed files in gcc-2.95.2.tar.gz, instead of binary garbage. However, to enable this facility, less has to invoke a sub-shell. If that sub-shell writes anything to standard output, you'll see that output instead of your file.


Based in discussion in the comments, I don't know what's causing the problem, but I've come up with a workaround.

I'm unable to reproduce the problem myself, even with tcsh 6.13.00 (which is fairly old, BTW).

But creating the alias from .login, or from a file sourced from .login, seems to avoid the problem.

In my own experiments, I aliased postcmd to a command that updates the xterm title bar with a high-resolution timestamp. With the alias defined in my .cshrc, the title bar updates rapidly as my shell starts, indicating that postcmd is executed even while init scripts are being executed, before the first interactive prompt appears. (Aliasing postcmd to something that appends information to a log file could help track this down.)

Since .login is sourced after .cshrc, moving the alias definition to .login means that fewer commands are executed with the alias in effect. That's not a bad idea anyway; you probably don't need the alias other than in a login shell.

My guess is that something in one of your startup scripts interacts with your postcmd alias in a way that messes up your terminal settings. If you're interested, you can probably try putting the alias definition in various places in your .cshrc, to see what command triggers the problem. (A divide-and-conquer approach means you won't have to perform a huge number of trials.)

It would be interesting to see if the problem still exists in later versions of tcsh. It could well be a tcsh bug, but I don't see anything relevant at http://bugs.gw.com/.