Subject: query current window title to stdout?

From: Michael Parson <[email-masked]>
Date: Fri, 15 Aug 2008 11:42:35 -0500

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`

So I could change that last echo to be more like

echo -ne "\ek$oldname\e\\"

However, it seems that just about every screen command only spit  
output to the status bar, hardline, or a new screen, except 'screen -l'.

Can this be done? or is the solution I've come up with going to be  
about as good as it gets?

-- 
Michael Parson
[email-masked]

_______________________________________________
screen-users mailing list
[email-masked]
http://lists.gnu.org/mailman/listinfo/screen-users

---

From: Micah Cowan <[email-masked]>
Date: Fri, 15 Aug 2008 12:06:40 -0700

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

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*".

- --
HTH,
Micah J. Cowan
Programmer, musician, typesetting enthusiast, gamer.
GNU Maintainer: wget, screen, teseq
http://micah.cowan.name/

---

From: Micah Cowan <[email-masked]>
Date: Fri, 15 Aug 2008 12:09:19 -0700

Micah Cowan wrote:
> feature.

Whoops! No, DON'T DO THAT.

I forgot that the SEARCH portion of the "SEARCH|NAME" syntax _must_ be
seen on the prompt, and before the user starts typing input. Screen
halts output until it sees what it wants to see. Sorry...

- --
Micah J. Cowan

---

From: Michael Parson <[email-masked]>
Date: Fri, 15 Aug 2008 16:01:23 -0500

> name of the file he is editing.

<snip>

> about as good as it gets?

working with a friend, we came up with this:

_svim () {
         /usr/bin/screen -X msgwait 5
         echo -ne "\ekediting $1\e\\"
         /usr/bin/vim $1
         exit
}

svim () {
         tname=`basename $(mktemp -u)`
         /usr/bin/screen -t $tname
         /usr/bin/screen -X msgwait 0
         /usr/bin/screen -X at "$tname" stuff "_svim $1^M"
}

Which lets me do fun things like:

for ij in foo1.pl foo2.pl foo3.pl do; svim $ij; done

And have 3 new windows pop open with the new files in them, window  
titles set appropriately, should be race-condition safe.

This is all on a Linux box, using bash, and has the gnu mktemp  
installed.  Other systems will have to be modified as needed.

-- 
Michael Parson
[email-masked]

---

From: Christian Ebert <[email-masked]>
Date: Fri, 15 Aug 2008 23:50:46 +0200

* Michael Parson on Friday, August 15, 2008 at 11:42:35 -0500
> However, it seems that just about every screen command only spit output 
> to the status bar, hardline, or a new screen, except 'screen -l'.
> 
> Can this be done? or is the solution I've come up with going to be about 
> as good as it gets?

If it's for vim, it can be (almost) done. I have the follwoing in
.vimrc:

if &term =~ '^screen'
  set title
  " VimTip #1126
  set t_ts=^[k
  set t_fs=^[\
  let &titleold = fnamemodify(&shell, ":t")
endif

The "^[" is entered Ctrl-V [

c
-- 
Vim plugin to paste current GNU Screen buffer in (almost) any mode:
<http://www.vim.org/scripts/script.php?script_id=1512>