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

RE: how can I make a local directory be a symlink to a remote one?



> 
> How can I make a local directory be a virtual symbolic link to a
remote
> directory? (Where "remote" means accessible via ssh(1) and friends.)
> 
> For example, I'd like file copies (cp(1)'s) to and from my local ~/foo
> directory to actually be scp(1)'s to and from my remote ~/foo
directory,
> and ls(1)'s of my local ~/foo directory to actually be ssh(1)-invoked
> ls(1)'s of my remote ~/foo directory. In the first case, I could
> implement this with a script that, say, checked for commands of the
form
> "cp file ... ~/foo", rewriting them as "scp file ... rhost:~/foo", but
> that seems inelegant.
> 
> Can anyone point me to a Zsh idiom or meme that would permit me to do
> this? Or is this better implemented in some non-Zsh way?
> 

I do not see anything inelegant in zsh functions, but ...

It is of course possible to write shell functions for ls, cp, mv &
friends that would intercept access to specific directories and call ssh
for them. But you of course understand that it will work only when you
use these commands, more over, only when you use them from inside of
shell. Any other program trying to access these directories will see
just a normal local ones.

To do what you want transparently you need one of

- shared library that will be preloaded and will intercept syscalls for
open, creat, stat, etc in specific directories (you may check SAMBA for
example implementation, they do exactly the same for SMB access). This
solution unfortunately is not truly portable because not every system
supports library preloading, besides it does not work for statically
linked programs.

- implement new file system in kernel.


-andrey



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