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

Re: ssh and chdir to my PWD on the local computer



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.



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