information in xterm's title & tcsh & less

to have a computer name and path on the title
of xterm i do have following in my .tcshrc:

if ($?TERM) then
  alias monas_private_title   'echo -n "\033]0;`hostname`:`pwd`\007"'

  alias cd 'cd \!*; monas_private_title'
#  monas_private_title # <---- mark
endif

if I uncomment marked line and try to "less some_file" - I get one line with ESC and no text of that some_file.

if I leave as it is - I don't get info until first cd.

Question: Why do I get that crap? How do I have information right after login.

info about sw (if that matters)
tcsh: version tcsh 6.08.00 (Astron) 1998-10-02 (i586-intel-linux) options 8b,nls,dl,al,color

xterm: AIX 4.3.3

connection: ssh-1.2.27
LVL 3
monasAsked:
Who is Participating?
 
jlevieConnect With a Mentor Commented:
Okay, what I thought was probably happening was that the highly non-portable behaviour of echo was at the root of the problem, but I wanted to see your .tcshrc to make sure.

The behavour of echo for anything except plain strings varies according to platform and shell and shell implementation. The correct way, when using more than one platform is to carefully collect each thing that's OS or shell version dependant into a section that's only used for that particular OS.

I've put a template of such a shell init file below that you can fill in with what you need in the appropriate sections. It may have a typo or two in it as I stripped a bunch of stuff out of an existing .cshrc. Note the different ways I've defined the "title" command for those OS's I could easily check.

--- Begin template ---
#
# Figure out what OS this is
#
switch (`uname -s`)
  case SunOS:
    switch (`uname -r`)
      case 5.*:
        setenv OS SOLARIS
        switch (`uname -p`)
          case sparc:
            setenv CPU SPARC
            breaksw
          case i386:
            setenv CPU INTEL
            breaksw
        endsw
        breaksw
      case 4.1.3_U1:
        setenv OS SUNOS
        breaksw
    endsw
    breaksw

  case Linux:
    setenv OS LINUX
    breaksw

  case IRIX:
    setenv OS IRIX
    setenv CPU IRIX32
    breaksw

  case IRIX64:
    setenv OS IRIX
    setenv CPU IRIX64
    breaksw

  default:
    echo "Who knows what OS this is"
endsw

#
# Do platform specific & generic setups (path, env vars, etc.)
# other than what's needed for an interactive shell
#
switch ($OS)
  case SOLARIS:
    alias title '/bin/echo "\033]0;`hostname`:pwd`\007\c"'
    setenv path (....)
    setenv MANPATH (...)
    setenv LD_LIBRARY_PATH (...)
    ...
    breaksw
  case SUNOS:
    setenv path (....)
    setenv MANPATH (...)
    setenv LD_LIBRARY_PATH (...)
   ...
   breaksw
  case LINUX:
    alias title '/bin/echo -n -e "\033]0;`hostname`:pwd`\007"'
    setenv path (....)
    setenv MANPATH (...)
    setenv LD_LIBRARY_PATH (...)
    ...
    breaksw
  case IRIX:
    alias title '/bin/echo -n "\033]0;`hostname`:pwd`\007"'
    setenv path (...)
    ...
    breaksw
  case IRIX64:
    alias title '/bin/echo -n "\033]0;`hostname`:pwd`\007"'
    setenv path (...)
    ...
    breaksw
endsw
#
# Some generic applicable to all platforms
#
umask 002
....

#
# Only execute what follows for interactive shells
#
if ($?USER == 0 || $?prompt == 0) then
  exit
endif

set history = 32
set savehist = 32
set prompt = "AK@%m( \! )%.03 %#%#"                                            ...

#
# A few generic aliases and the OS dependant ones
#
alias ls 'ls -F'
if ($?TERM) then                                                                  alias cd 'cd \!*; title'
   title
endif                                                                          ...

switch ($OS)
  case SOLARIS:
    setenv LESS -cej1s
    alias more less
    alias psg 'ps -ef | fgrep \!* | fgrep -v fgrep'
    switch ($CPU)
      case SPARC:
        setenv FMHOME /opt/Frame
        alias maker '$FMHOME/bin/maker'
      breaksw
    endsw
    ...
    breaksw

  case SUNOS:
    ...
    breaksw

  case Linux:
    setenv LESS -cej1s
    alias psg 'ps -ef | fgrep \!* | fgrep -v fgrep'
    ...
    breaksw

  case IRIX:
    setenv LESS -cej1s
    alias more less
    alias psg 'ps -ef | fgrep \!* | fgrep -v fgrep'
    ...
    breaksw

  case IRIX64:
    setenv LESS -cej1s
    alias more less
    alias psg 'ps -ef | fgrep \!* | fgrep -v fgrep'
    ...
    breaksw
endsw

#
# If I have a host rc file execute it now. This gives
# me a place to put stuff that's specific to a particular
# host.
#
if (-f $HOME/.host_csh) then
  source $HOME/.host_csh
endif
0
 
jlevieCommented:
Which is the local machine and which is the remote that the .tcshrc file is on?
If you open an xterm on the remote and issure the command "echo -n "\033]0;`hostname`:`pwd`\007" what happens?
0
 
monasAuthor Commented:
OK, that was when AIX runs X+xterm, linux - tcsh.

But right now I have checked on another linux box where X, xterm adn tcsh runs on the same machine. Results:

when I have monas_private_title in .tchsrc - I get

ESC]0;ak:/home/kaspar^G
/etc/passwd line 1/1 (END)

to "less /etc/passwd"

when title line is missing - I get less working. **Even** if I enter manually this command before issuing less!

What's going on?!?!
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
monasAuthor Commented:
Oh, linux in both cases is slackware 7 with 2.2.14 kernel
0
 
jlevieCommented:
Can I see your entire .tcshrc file, please? You can paste it into a comment ore email it to jlevie@bellsouth.net.
0
 
vrmudsCommented:
I think you are looking for this:
This works under korn, and changes a little for different shells.
^v]2;ak:$PATH^g >
or
CNTL-[]2;whateverCNTL-g
One of these will work.
0
 
monasAuthor Commented:
Thank you jlevie!

The problem was that I missed to exit before interactive stuff in not interactive shells. It happened that LESSPIPE was set somewhere in host-wide config; it's value was "|lesspipe.sh" and I suspect that seeing | less put all the job to new instance of shell. less shows original file only in case when lesspipe outputs nothing, but in my case my shell startup had outputed title - therefore things were bad.

Thanks again for pointing out how to write correct startup files!

All the best
      -- monas
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.