1

I am executing all my code on a remote machine. I mounted the remote filesystem using sshfs on my laptop, so I can use my own preferred text editors and such. I.e. in my terminal window I run an ssh session where I enter my commands, and in my local editor I have a mounted file opened.

The only tedious thing is that every time I want to open a file or directory, I have to navigate all the way to the local mounted directory in a new terminal window.

Is there a neat way I can define a command / keyboard shortcut so that I can immediately open a local file/directory from my ssh session?

I thought of:

  • A script that sends a command via ssh to my own laptop from the remote
  • Somehow using the pasteboard (doing pwd on the remote, copying that to the pasteboard, translate it to a path to the local mounted filesystem)
  • Using applescript (since I am working on a Mac) and making a new service for the Terminal.app

but so far I have not been able to solve the problem.

  • /type/in/the/full/path/for/the/file – Skaperen Aug 4 '16 at 6:10
  • ssh -t user@ipaddress '/pathtothescript' ? – LinuxSecurityFreak Aug 4 '16 at 6:53
  • What sort of command/script are you trying to run, and why can't you run it on the local machine directly? Why does the machine that you've ssh-ed to need to get involved? – JigglyNaga Aug 4 '16 at 7:13
1

If you have X11 on the remote and you connect to it with ssh -X then you already have a reverse channel back to your local machine. Write yourself a tiny script on the remote, eg fff:

#!/bin/bash
mountpoint=/mnt/remote
case $1 in
/*)  file="$1" ;;
*)   file="$PWD/$1" ;;
esac
echo "$mountpoint/$file" | xsel -p

Then when you want to pass a filename back, on the remote type fff and the name of the file to edit using tab completion etc. The script will prefix the filename with the mount point and set the X11 primary selection to the result.

On your local machine you can now simply type vi and press the mouse paste button to add the correct local equivalent filename to the command.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.