[Top][All Lists]

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

Re: Get current working directory from another screen window

From: Michael Parson
Subject: Re: Get current working directory from another screen window
Date: Fri, 24 Jun 2011 10:30:59 -0500 (CDT)
User-agent: Alpine 2.00 (NEB 1167 2008-08-23)

On Wed, 22 Jun 2011, Tomasz Muras wrote:


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 

-- begin chscdir --

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

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:


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

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

Michael Parson
Austin, TX

reply via email to

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