Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

ssh and chdir to my PWD on the local computer



I wanted to be able to ssh to another computer and immediately chdir
to the same directory that I was using locally.

I came up with _a_ solution, but I'm not sure if it's a good one, or
if there would be other ways to do this more easily/better, so I'm
sharing it here.

Since all of the computers are under my own control, I was able to
accomplish this by editing the ssh_config and sshd_config files to add
`SendEnv CWD` and `AcceptEnv CWD` respectively.

/etc/ssh/ssh_config:   SendEnv CWD

/etc/ssh/sshd_config: AcceptEnv CWD

I also added this to the end of my .zshrc file:

if [[ "$CWD" != "" ]]
then
    echo "changing to '$CWD'"
    cd "$CWD"
fi

Then I was able to use this by connecting to my remote computer like this:

        CWD=$PWD ssh remote.host.tld

The last part seems a little clunky, although I'm sure I could make a
function or something, but I wondered if anyone else has solved this a
different way, and if so, how… or does anyone have a suggestion how to
do this differently / better?

Thanks for your time

Tj


--
TJ Luoma
TJ @ MacStories
Personal Website: luo.ma (aka RhymesWithDiploma.com)
Twitter: @tjluoma



Messages sorted by: Reverse Date, Date, Thread, Author