I set up my tcsh xterm to update the titlebar on “postcmd” with the name of the last command that was run and the directory.
This is similar to what I had (minimal example to reproduce):
alias postcmd 'echo -n "\033]0;hello_world\007";'
(note that this alias is in my .cshrc file. If just I type this on the command line, than it works 100% properly)
This successfully updates the xterm titlebar to say “hello_world” after every command that I run, except for less When I run less, I get the following terminal output:
>less abc.txt
ESC]0;hello_world^GESC]0;hello_world^GESC]0;hello_world^GESC]0;hello_world^GESC]0;hello_world^GESC]0;hello_world^GESC]0;hello_world^GESC]0;hello_world
^GESC]0;hello_world^GESC]0;hello_world^GESC]0;hello_world^GESC]0;hello_world^GESC]0;hello_world^G...
(END)
The file never actually opens, it just prints this garbage string and I have to CTRL-C to cancel it. Is the bell or escape character messing up the initialization of less somehow? Any idea how I can modify this to not break less? I could just as easily use another editor, but sometimes I need to share my console with other engineers for debugging and I don’t want to confuse them if they choose to run less.
This is the actual code I am using, which has the same issue as the simple hello_world example:
alias postcmd 'set HIST = `history -h 1`; printf "\033]0;%s\007" "xterm: $HIST @ $cwd ";'
=====EDIT=====
Some additional info:
> alias less
> echo $LESS
LESS: Undefined variable
> echo $TERM
xterm
>less --version
less 382
Copyright (C) 2002 Mark Nudelman
less comes with NO WARRANTY, to the extent permitted by law.
For information about the terms of redistribution,
see the file named README in the less distribution.
Homepage: http://www.greenwoodsoftware.com/less
>tcsh --version
tcsh 6.13.00 (Astron) 2004-05-19 (x86_64-unknown-linux) options 8b,nls,dl,al,kan,rh,color,dspm,filec
=== MORE EDIT ===
On further debugging, I find that the problem only occurs when I put the command in my .cshrc file. If I uncomment the alias from .cshrc, and simply type the alias on the command line, then it works properly with less.
Also, having put the alias in my .cshrc , if I unalias it, it still breaks less even after being unaliased. So it seems the problem is not coming from the presence of the alias, but from being aliased while .cshrc is being executed on terminal creation?
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
postcmdto a command that updates thextermtitle bar with a high-resolution timestamp. With the alias defined in my.cshrc, the title bar updates rapidly as my shell starts, indicating thatpostcmdis executed even while init scripts are being executed, before the first interactive prompt appears. (Aliasingpostcmdto something that appends information to a log file could help track this down.)Since
.loginis sourced after.cshrc, moving the alias definition to.loginmeans 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
postcmdalias 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/.