views:

864

answers:

10

I'm doing my development work on my Windows machine, but my compiling on a remote Linux machine. What I currently do is start an X server on Windows, ssh into the Linux machine, then do the development remotely.

What I'd like to do is edit my source on the Windows machine, and have it automatically copy files over to the Linux system when I save. I'd also like for my built-in compilation commands to perform a build on the remote system.

If it makes a difference, the source is all in C, using GCC. In descending order of preference, I have Emacs, Vi, and Netbeans on my desktop, and am willing to install another IDE for a last resort.

A: 

One solution might be to have some sort of polling app that checks the timestamp on the files to see if they have changed. If they have then get it to save and then compile. Kinda hackish this way but it would be workable.

Hyposaurus
+5  A: 

I would look into continuous integration for your environment. This way you can commit the changes to source control, and have the linux box act as a build server. You can have tests associated and other related interesting stuff you want to be run on the builds.

Update 1: Also this might work for you: http://metamod-p.sourceforge.net/cross-compiling.on.windows.for.linux.html (it is also worth a try doing some searches on similar tools)

eglasius
But I don't wish to depend on check ins for build; I wish to build first to make sure it is good before the check in.
Brian Carlton
+2  A: 

You could try sharing a disk between your Linux and Windows machines using Samba or something like that. Then you could edit on your local machines and the files would be visible immediately on the remote machine since the drive would be visible to both.

Where I work we have all files on NFS that is accessible from all Linux machines and Windows machines. I don't know how hard it is to set that up since I work in a large corporation and IT is abstracted away from me, but simple disk sharing should be pretty straightforward.

Nathan Fellman
+1  A: 

Can you just use a samba share to save the files directly on the remote machine? I often do PHP this way.

Then just have a putty window open to run commands on the remote box.

Or am I missing something?

cletus
+1  A: 

Why do you start an X server on Windows? Personally, I would set up a Linux VM with VMware or whatever your favorite VM technology is (VMware is free and works well). Then choose any Linux distribution you want. You just need very basic functions, mostly the standard "toolchain." You could pick Centos, Ubuntu, Fedora, Debian, whatever. I usually use Centos or Debian. Set it up, and just use PuTTY into your VM. From there, you can scp files to your remote server and so forth. This way you don't have to bother with cygwin or an X server or any of that.

BobbyShaftoe
+4  A: 

Other have suggested SAMBA which may not be feasible on your Linux box. A good alternative is to use Dokan SSHFS on your Windows box to mount a remote directory over SSH.

innaM
+6  A: 

This is certainly doable in vim. You can use the scp:// protocol within vim to edit remote files, and set up a command that writes a local copy. You can also change what program vim uses for :make to do an ssh make instead on your server.

You'll need to set up your ssh-keys to keep this painless (otherwise you'll be entering your password all the time) but that's fairly easy.

Another alternative would be to push to a remote repos as part of your make command, instead of editing remotely.

If you need more detail on how to do any of this, leave a comment, and I'll fill in tomorrow when I'm at a real computer.


EDIT: (okay, two days later)

First, using the scp:// protocol within vim. From :help netrw-start (or down the page from :help scp)

Netrw supports "transparent" editing of files on other machines using urls (see |netrw-transparent|). As an example of this, let's assume you have an account on some other machine; if you can use scp, try:

vim scp://hostname/path/to/file

Want to make ssh/scp easier to use? Check out |netrw-ssh-hack|!

You can also use scp:// paths in :edit commands, or really anywhere that you could use a normal path.

And, from the mentioned :help netrw-ssh-hack, instructions on how to set up your ssh keys:

IMPROVING BROWSING *netrw-listhack* *netrw-ssh-hack* {{{2

Especially with the remote directory browser, constantly entering the password is tedious.

For Linux/Unix systems, the book "Linux Server Hacks - 100 industrial strength tips & tools" by Rob Flickenger (O'Reilly, ISBN 0-596-00461-3) gives a tip for setting up no-password ssh and scp and discusses associated security issues. It used to be available at http://hacks.oreilly.com/pub/h/66 , but apparently that address is now being redirected to some "hackzine". I'll attempt a summary based on that article and on a communication from Ben Schmidt:

(1) Generate a public/private key pair on the local machine (ssh client):

  ssh-keygen -t rsa

(saving the file in ~/.ssh/id_rsa as prompted)

(2) Just hit the when asked for passphrase (twice) for no passphrase. If you do use a passphrase, you will also need to use ssh-agent so you only have to type the passphrase once per session. If you don't use a passphrase, simply logging onto your local computer or getting access to the keyfile in any way will suffice to access any ssh servers which have that key authorized for login.

(3) This creates two files:

  ~/.ssh/id\_rsa
  ~/.ssh/id\_rsa.pub

(4) On the target machine (ssh server):

 cd
 mkdir -p .ssh
 chmod 0700 .ssh

(5) On your local machine (ssh client): (one line)

 ssh {serverhostname} cat '>>' '~/.ssh/authorized\_keys2' < ~/.ssh/id_rsa.pub

or, for OpenSSH, (one line)

 ssh {serverhostname} cat '>>' '~/.ssh/authorized\_keys' < ~/.ssh/id_rsa.pub

You can test it out with

 ssh {serverhostname}

and you should be log onto the server machine without further need to type anything.

If you decided to use a passphrase, do:

 ssh-agent $SHELL
 ssh-add
 ssh {serverhostname}

You will be prompted for your key passphrase when you use ssh-add, but not subsequently when you use ssh. For use with vim, you can use

 ssh-agent vim

and, when next within vim, use

 :!ssh-add

Alternatively, you can apply ssh-agent to the terminal you're planning on running vim in:

 ssh-agent xterm &

and do ssh-add whenever you need.

For Windows, folks on the vim mailing list have mentioned that Pageant helps with avoiding the constant need to enter the password.

Kingston Fung wrote about another way to avoid constantly needing to enter passwords:

In order to avoid the need to type in the password for scp each time, you provide a hack in the docs to set up a non password ssh account. I found a better way to do that: I can use a regular ssh account which uses a password to access the material without the need to key-in the password each time. It's good for security and convenience. I tried ssh public key authorization + ssh-agent, implementing this, and it works! Here are two links with instructions:

For making on remote systems, you need to set your makeprg variable to do an ssh make. From :help makeprg

Program to use for the ":make" command. See |:make_makeprg|. This option may contain '%' and '#' characters, which are expanded to the current and alternate file name. |:_%| |:_#| Environment variables are expanded |:set_env|. See |option-backslash| about including spaces and backslashes.

Note that a '|' must be escaped twice: once for ":set" and once for the interpretation of a command. When you use a filter called "myfilter" do it like this:

 :set makeprg=gmake\ \\\|\ myfilter

The placeholder "$*" can be given (even multiple times) to specify where the arguments will be included, for example:

 :set makeprg=latex\ \\\\nonstopmode\ \\\\input\\{$*}

This option cannot be set from a |modeline| or in the |sandbox|, for security reasons.

rampion
I'd love to see details on using the scp:// protocol. Might be nice to include a pointer to ssh-keys instructions as well.
dreeves
+1  A: 

Set a source control system and use it. Then you can just make a commit after saving in your IDE, and on server you can have something happening on-commit.

This can trigger tests, build, mail any errors to you...

kender
+9  A: 

One option is to use the TRAMP remote-editing package (built into Emacs 22 and newer, and you can install it into older versions). Every time you save your file, Emacs sends its contents over ssh (by default; of course every detail is totally configurable) to the Linux machine. Commands like M-x compile and M-x grep are TRAMP-aware and execute on the remote host.

Jouni K. Seppänen
A: 

I personally use XMing with PuTTY. I ssh using PuTTY while XMing is running. I can open up any editor (gvim, emacs, gedit, etc) and it will appear.

You will need to do some setup on PuTTY though:

  1. Expand Connection
  2. Expand SSH
  3. Click on X11
  4. Check the "Enable X11 Forwarding"
  5. In the text field for display location, enter (without quotes): "localhost:0"
  6. Save session and connect.
Ascalonian