(tcsh) postcmd alias for xterm titlebar breaks less texteditor

I set my tcsh xterm to update the header on "postcmd" with the name of the last command and directory started.

This is similar to what I had (minimal example to play):

alias postcmd 'echo -n "\033]0;hello_world\007";'

(note that this alias is in my .cshrc file. If I just type it on the command line, then it works 100%)

This successfully updates the xterm header header 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 opens, it just prints this garbage line, and I need CTRL-C to undo it. Is a bell or a winning character somehow ruining the initialization? Any idea how I can change this so as not to break less ? I could just use a different editor, but sometimes I need to share my console with other engineers for debugging, and I don't want to confuse them if they decide to run less .

This is the actual code that I am using that has the same problem as the simple hello_world example:

 alias postcmd 'set HIST = `history -h 1`; printf "\033]0;%s\007" "xterm: $HIST @ $cwd ";' 

===== ===== EDIT Additional information:

 > 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 ===

With further debugging, I find that the problem occurs when I put this command in a .cshrc file. If I uncomment the alias from .cshrc and just type the alias on the command line, then it works correctly with less.

Also, by putting an alias in my .cshrc, if I refuse it, it will still break less even after it is unaliased. Thus, it seems that the problem does not arise due to the presence of an alias, but from aliases, while .cshrc is executed when creating the terminal?

+4
source share
2 answers

Based on the discussions in the comments, I don't know what causes the problem, but I came up with a workaround.

I can not reproduce the problem myself, even with tcsh 6.13.00 (which is pretty old, BTW).

But creating an alias from .login or from a file derived from .login seems to fix the problem.

In my own experiments, I changed postcmd to a command that updates the xterm title bar with a high resolution timestamp. With an alias defined in my .cshrc , the title bar updates quickly as my shell starts, indicating that postcmd is executed even during initialization scripts until the first interactive prompt appears. (Merging postcmd with adding information to the log file can help trace this.)

Since .login obtained after .cshrc , moving the alias definition to .login means that fewer commands are executed with a valid alias. This is not a bad idea; you probably don't need an alias except in the login shell.

My assumption is that something in one of your startup scripts interacts with your postcmd alias in a way that violates your terminal settings. If you're interested, you can try putting the alias definition in different places on your .cshrc to see which command is causing the problem. (The split-and-win approach means you don’t have to do a lot of testing.)

It would be interesting to know if a problem exists in later versions of tcsh. It may be a tcsh error, but I don't see anything meaningful at http://bugs.gw.com/ .

+1
source

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

From your site:

Less command

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

If the .cshrc, .profile or any other shell launcher file in your home directory prints any text, this text will be displayed less instead of your file. To get rid of this behavior, check to see if you can write to standard output before you print anything. For example, suppose you use the tcsh shell and you put the following instructions in your .cshrc file:

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

Replace it as follows:

  # "-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 

Equivalent test in sh-style shell:

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

FAQ in the FAQ: Why is it less?

RedHat Linux has fewer options for displaying other types of files in addition to plain text. For example, if you enter:

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

you will see a list of compressed files in gcc-2.95.2.tar.gz instead of binary garbage. However, to include this object, it is less necessary to refer to a sub-shell. If this sub-shell writes anything to standard output, you will see this output instead of your file.

+2
source

Source: https://habr.com/ru/post/1398663/


All Articles