Re: Get current working directory from another screen window

Michael Parson <[email protected]>
Newsgroups gmane.comp.gnu.screen.user
Message-ID <[email protected]>
On Wed, 22 Jun 2011, Tomasz Muras wrote:

> Hello,
>
> I'm wondering if something like this would be possible:
> I would like to quickly switch to the same current working directory
> as in another screen window. Would it be possible to read cwd of
> another window?

It takes a bit of screen scripting, but this took me about 5 minutes to throw together:

-- begin chscdir --
#!/bin/sh

screen -X msgwait 0
screen -X at "$1" stuff ""
screen -X at "$1" stuff "pwd > $TMPDIR/buffer ^M"
screen -X readbuf
screen -X stuff "cd "
screen -X paste .
screen -X removebuf
screen -X msgwait 4

-- end chscdir --

I redefine the buffer file in my .screenrc to be in $TMPDIR/buffer
rather than the default of /tmp/screen-exchange.  Adjust this as
necessary.

This just requires that you know the screen number of the screen you
want to match, and that it be at a shell prompt.  It can't magically
know the dir if that other screen is in a vi session or something.

The control chars above need to be entered with a ^V first (^V^U) so
that they get inserted rather than evaluated.

To use:

In screen 4, you're sitting in some deep directory, say something like:

/usr/local/src/mynewproj/src/modules/funstuff

And in screen 8, you're in your home directory, but want to be in the
same dir as screen 4.

While sitting in screen 8, type:

chscdir 4

And the command 'cd /usr/local/src/mynewproj/src/modules/funstuff'
should show up on your current screen, and you should now be in that
directory.

If you were to pop back over to screen 4, you would see the pwd command
that was executed.

-- 
Michael Parson
[email protected]
Austin, TX
KF5LGQ
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.