2

I find myself performing this REPL-like action quite often:

vim foo.sh
scp foo.sh host:/tmp/foo.sh
ssh host /tmp/foo.sh
# realizing it wasn't quite right
vim foo.sh
scp foo.sh host:/tmp/foo.sh
ssh host /tmp/foo.sh
# repeat many times

I was about to plow away at writing a shell script to make this simpler, but was wondering if someone smarter than me solved this problem more elegantly.

What's your solution? Besides emacs :)

EDIT: Why not just edit my file on the remote host? Simple, the hosts receiving my scripts won't always have a dev environment set up, so in this case host might not have all of my vim customizations; sometimes it'll be C code instead of a shell script, which means my workflow looks like:

vim foo.c
make
scp foo host:/tmp/foo
ssh host /tmp/foo
# repeat

That's why. I guess I want something with an interface like:

edit_loop foo.c --make --copy-and-run=host:/tmp/foo

What do you think?

mbac32768
  • 858
  • 1
  • 7
  • 13

3 Answers3

3
ssh remotehost bash < foo.sh
Ignacio Vazquez-Abrams
  • 45,939
  • 6
  • 79
  • 84
2

Step 1: Mount your remote host as a local folder using SSH-FUSE.

Step 2: vim ssh-mount/foo.sh

Step 3: From a second terminal, or forking from vim, run ssh host:.../foo.sh

Rinse and repeat.

Link: http://fuse.sourceforge.net/sshfs.html

mpbloch
  • 982
  • 9
  • 14
  • 1
    In fact, if you can run make with local tools, then you can use SSH-FUSE as in the C example, keep the source remote-mounted, and use local build tools. – mpbloch Jun 21 '10 at 14:42
2

You don't need to repeatedly scp to the server; let Vim handle that for you automatically!

vim scp://user@host/path/to/file

You can then run ssh user@host in a separate terminal, and run make or /path/to/file there.

If you need a build environment that is not available on the server, you should instead check out the previous answer about sshfs.

jabirali
  • 191
  • 4