query current window title to stdout?

View: New views
5 Messages — Rating Filter:   Alert me  

query current window title to stdout?

by Michael Parson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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







_______________________________________________
screen-users mailing list
screen-users@...
http://lists.gnu.org/mailman/listinfo/screen-users

Re: query current window title to stdout?

by Micah Cowan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

-----BEGIN PGP SIGNED MESSAGE-----
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*".

- --
HTH,
Micah J. Cowan
Programmer, musician, typesetting enthusiast, gamer.
GNU Maintainer: wget, screen, teseq
http://micah.cowan.name/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFIpdPA7M8hyUobTrERAkd7AJ0R4qOKO6y/fhvyzSQCk98879uNHQCghPou
/xFjhSyOzDFJDHtugMBeT74=
=GrXk
-----END PGP SIGNATURE-----


_______________________________________________
screen-users mailing list
screen-users@...
http://lists.gnu.org/mailman/listinfo/screen-users

Re: query current window title to stdout?

by Micah Cowan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Micah Cowan wrote:
> However, you might take advantage of the special "Dynamic Titles"
> 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
Programmer, musician, typesetting enthusiast, gamer.
GNU Maintainer: wget, screen, teseq
http://micah.cowan.name/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFIpdRf7M8hyUobTrERApmjAJ9ud5RrUAYjQlTwjNWAw+xFF3pnDwCeMwvj
CNPah7RWaIvRjPHNIpLDSqY=
=Ghjj
-----END PGP SIGNATURE-----


_______________________________________________
screen-users mailing list
screen-users@...
http://lists.gnu.org/mailman/listinfo/screen-users

Re: query current window title to stdout?

by Michael Parson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Aug 15, 2008, at 11:42 AM, 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.

<snip>

> Can this be done? or is the solution I've come up with going to be  
> 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
mparson@...







_______________________________________________
screen-users mailing list
screen-users@...
http://lists.gnu.org/mailman/listinfo/screen-users

Re: query current window title to stdout?

by Christian Ebert :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

* Michael Parson on Friday, August 15, 2008 at 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?

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>


_______________________________________________
screen-users mailing list
screen-users@...
http://lists.gnu.org/mailman/listinfo/screen-users
LightInTheBox - Buy quality products at wholesale price!