screen-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Script knowing if in screen / screen window correponding to tty


From: Thomas Köhler
Subject: Re: Script knowing if in screen / screen window correponding to tty
Date: Sun, 11 Jul 2004 20:02:30 +0200
User-agent: Mutt/1.5.4i

Hi,

Buddy Burden wrote:
> Guys,
> 2) Is there any way to know what screen window corresponds to a given 
> tty?  I generally have so many screen windows open that it's easy for me 
> to lose track of what's where.  I often find that when I vi a file, it 
> tells me I'm already vi'ing it somewhere else.  It gives me a pid, and 
> from that I can get a tty, but I don't know where to go from there. 
> (I'm not necessarily looking for an automated solution to this one.)  If 
> this _is_ possible, then I further wonder if there's a way to get the 
> tty printed on the windowlist--that would be particularly nifty.

Well... You could always setup your shell's prompt to contain
something like '<esc>k$tty<esc>\' and $tty be your tty name.
For example, I just added this to my .zshrc precmd() function:
PROMPT="k$(tty)\\%~> "
Voila, the title of a new screen window looks like "/dev/pts/3"
:)
You might want to play around a bit with this. In zsh, you could
try something like this:

  function preexec {
     # let's define a local variable
     local y
     # tricky: y is an array
     # It is defined by using $1 and splitting it at ' ' (whitespace)
     # Result: $y is an array that consists of all of the words of the command 
line
     y=(${(s: :)1})
     # take the first element of that array and put it into the window title
     # together with the tty name
     echo -n "k$y[1] ($(tty))\\"
  }
  function precmd {
     # just tell the user we're back to zsh ;-)
     # together with the tty name
     PROMPT="kzsh ($(tty))\\%~> "
  }

Voila... you always see the currently running command name
together with the tty name. While one window title may look like
    zsh (/dev/pts/13) 
another one looks like
    slrn (/dev/pts/14)

If you're not using zsh, you'd have to check your favorite
shell's possibilities... Perhaps you can come up with something
similar...

> TIA for any help.

HTH,
Thomas

-- 
 Thomas Köhler       Email:       address@hidden
     <><             WWW:              http://gott-gehabt.de
                     IRC:                           tkoehler
                     PGP public key available from Homepage!

Attachment: signature.asc
Description: Digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]