Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
TCSH screen/xterm title settings.
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
rcs
n00b
n00b


Joined: 22 Jul 2004
Posts: 5

PostPosted: Thu Jul 22, 2004 4:48 pm    Post subject: TCSH screen/xterm title settings. Reply with quote

I like useful titles on windows. Yesterday, I went on a quest.


I came back in victory.

In your .tcshrc:
Code:
# Set xterm/screen titles to something useful.
if ( $?TERM ) then
  switch ( $TERM )
    case xterm*:
    case rxvt:
    case eterm:
      alias precmd 'echo -n "\033]2;${USER}@${HOST}: $cwd\007"'
      alias jobcmd 'echo -n "\033]2;\!#\007"'
      breaksw

    case screen:
      alias precmd 'echo -n "\033]2;${USER}@${HOST}: $cwd\007"; echo -n "\033ktcsh\033\\"'
      alias jobcmd 'echo -n "\033]2;\!#\007"; echo -n "\033k\!#:0\033\\"'
      breaksw

    default:
      # alias cwdcmd 'echo "Directory: $cwd"'
      unalias cwdcmd
      breaksw
  endsw
  cd .
endif

alias rm '/bin/rm -i'
unalias cp
unalias mv
alias ls '/bin/ls --color'


In your .screenrc:
Code:
hardstatus string '%h  [%-w(%n %t)%{-}%+w]'



Nifty line noise, eh?

To break it down. "\033]2;" is the escape code to hit the xterm/aterm/whatever title. Inside screen, that means the %h in the hardstatus line. So when you're in an xterm, that hits the escape code, expands "${USER}@${HOST}: $cwd" (to 'rcs@damascus: /home/rcs', for instance), then ends the escape with \007.

That's for the precmd (man tcsh) that is the special alias executed before every prompt print.

For jobcmd (man tcsh) that is executed before every non-builtin command, we have similar, but the string is "\!#". The escape is necessary to prevent tcsh from expanding it to soon. !# is equal to the current history item, the command you just ran. So
Code:
echo -n "\033]2;\!#\007"
pushes the command that is running, including arguments, into the title bar.


Alright. Now for screen.

Inside the screenrc, the "hardstatus string" command sets up the format for the hardstatus line. A line that can be always displayed. %h for the thing running inside screen to set, %-w for all screens before current, %n for number of current screen, %t for title (screen set!) of current screen, %+w for all screens after current. (man screen, "STRING ESCAPES")

You end up with something like:
Code:
rcs@damascus: /home/rcs [0 top (1 tcsh) 2 updatedb]
in your titlebar, showing you currently in a tcsh screen, with top the screen before, and updatedb running in the next.

Inside each screen, jobcmd and precmd run like before. Except instead of just setting window title, we also set screen title, with the escape started by "\033k" and ended by "\033\". I like to set this title to tcsh when I'm at a prompt, and just the command name, otherwise. So we can't do it with all the arguments the way we did before, the screen listing would get messy.

So we use the fabulous tcsh, and we get "\!#:0", the first word of the current history item.

Gotchas:
    *Inside the /etc/screenrc file, I ended up copying the termcap, terminfo, and termcapinfo entries for xterm, and replacing the xterm on each line with "rxvt" which is the term type for both rxvt and aterm.

    *putty, an ssh client for Windows, gives off a term type of xterm-color. This is configurable in it, or while logged in through "setenv TERM xterm", and everything works as expected.


Questions, comments?

EDIT: I forget to explain the alias commands. I don't know why, but the standard aliases for tcsh had lots of problems when I did this. Removing them, or setting them back to reference the actual binaries, made it work.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum