[Top][All Lists]

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

Re: query current window title to stdout?

From: Micah Cowan
Subject: Re: query current window title to stdout?
Date: Fri, 15 Aug 2008 12:06:40 -0700
User-agent: Thunderbird (X11/20080707)

Hash: SHA1

Michael Parson wrote:
> I've got a user that wants to be able to, with a single command, rename
> the title for the current window when he edits a file to the name of the
> file he is editing.
> What I've come up with is a bash function:
> svim () {
>         echo -ne "\ekediting $1 \e\\"
>         /usr/local/bin/vim $1
>         echo -ne "\ekbash\e\\"
> }
> What I would like to be able to do, is query the title of the window
> before we rename it, so we can set it back to what it was after the
> editor quits.  something like:
> oldname=`screen -X windowname`

Well, one problem is that the STY env var doesn't provide enough
information for screen to determine what window it's running in. And, as
you point out, screen doesn't really do much in the way of printing
session information (that would be quite helpful on some occasions,
though; I'll have to file an RFE for that - it still wouldn't help you
with window names, though).

However, you might take advantage of the special "Dynamic Titles"
feature. Place something like:

  shelltitle "$ vim |bash"

in your screenrc file, and set your prompt so that it emits "\ek\e\\" at
the beginning of the prompt. Screen will show the title as "bash", but
when it sees a line containing "$ vim " in it, it will set the window
title to the word that follows the "$ vim " instead, until it sees the
"\ek\e\\" again, at which point it will revert the title back to "bash".

One disadvantage of this technique is that in order to keep this
behavior, changing titles means changing them to "$ vim |foo" rather
than just plain "foo".

Also, not that "$ vim " assumes that those literal characters will
appear somewhere; if color escape sequences also appear, those would
also have to be made part of the "$ vim " portion. If it ends up being
too difficult to handle that, a plain "vim " might work instead.

You'll probably want to protect your prompt by only inserting the
initial "\ek\e\\" if your .bashrc determines that $TERM matches the
pattern "screen*".

- --
Micah J. Cowan
Programmer, musician, typesetting enthusiast, gamer.
GNU Maintainer: wget, screen, teseq
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Mozilla -


reply via email to

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