zsh-users
 help / color / mirror / code / Atom feed
* ssh and chdir to my PWD on the local computer
@ 2019-07-19 17:40 TJ Luoma
  2019-07-19 21:45 ` Roman Perepelitsa
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: TJ Luoma @ 2019-07-19 17:40 UTC (permalink / raw)
  To: Zsh MailingList

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: ssh and chdir to my PWD on the local computer
  2019-07-19 17:40 ssh and chdir to my PWD on the local computer TJ Luoma
@ 2019-07-19 21:45 ` Roman Perepelitsa
  2019-07-20 16:36 ` gi1242+zsh
  2019-07-22 15:55 ` Philippe Troin
  2 siblings, 0 replies; 4+ messages in thread
From: Roman Perepelitsa @ 2019-07-19 21:45 UTC (permalink / raw)
  To: TJ Luoma; +Cc: Zsh MailingList

On Fri, Jul 19, 2019 at 7:41 PM TJ Luoma <luomat@gmail.com> wrote:
>
> I wanted to be able to ssh to another computer and immediately chdir
> to the same directory that I was using locally.

When I need to run some commands before an interactive SSH session, I
do it like this:

    ssh -t user@host "cd ${(q)PWD}; zsh -i"

It's quite flexible.

Roman.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: ssh and chdir to my PWD on the local computer
  2019-07-19 17:40 ssh and chdir to my PWD on the local computer TJ Luoma
  2019-07-19 21:45 ` Roman Perepelitsa
@ 2019-07-20 16:36 ` gi1242+zsh
  2019-07-22 15:55 ` Philippe Troin
  2 siblings, 0 replies; 4+ messages in thread
From: gi1242+zsh @ 2019-07-20 16:36 UTC (permalink / raw)
  To: zsh-users


On Fri, Jul 19, 2019 at 01:40:02PM -0400, TJ Luoma wrote:

> /etc/ssh/ssh_config:   SendEnv CWD
> 
> /etc/ssh/sshd_config: AcceptEnv CWD

I used to pass variables to ssh by editing the configs this way; but
having multiple machines (some of which I don't have root on) made it
too clunky.

Now I usually do

    ssh -t host VAR=value ... zsh

You can save that as a shell alias; or edit ~/.ssh/config and define
RemoteCommand for the hosts you want.

GI

-- 
If you are not part of the solution, you are part of the precipitate.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: ssh and chdir to my PWD on the local computer
  2019-07-19 17:40 ssh and chdir to my PWD on the local computer TJ Luoma
  2019-07-19 21:45 ` Roman Perepelitsa
  2019-07-20 16:36 ` gi1242+zsh
@ 2019-07-22 15:55 ` Philippe Troin
  2 siblings, 0 replies; 4+ messages in thread
From: Philippe Troin @ 2019-07-22 15:55 UTC (permalink / raw)
  To: TJ Luoma, Zsh MailingList

On Fri, 2019-07-19 at 13:40 -0400, TJ Luoma wrote:
> 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.

I use this function:

   scd() {
     local term=
     case $# in
       (0)
         echo "usage: $0 <host> [<command> [<arguments>...]]"
         return 1
         ;;
       (1)
         term=-t
         ;;
     esac
     local host=$1
     shift
     ssh $term $host cd ${(q)PWD} '&& exec $SHELL' ${1+-c} ${(qj: :)*}
   }

Phil.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-07-22 15:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-19 17:40 ssh and chdir to my PWD on the local computer TJ Luoma
2019-07-19 21:45 ` Roman Perepelitsa
2019-07-20 16:36 ` gi1242+zsh
2019-07-22 15:55 ` Philippe Troin

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).