Disclaimer: Pretty new to Emacs and running Spacemacs, have no idea what I'm doing with elisp.

We run all our projects under vagrant, so I'm interested in getting some things, such as inf-ruby-mode consoles, to ssh into my vagrant box before running their commands. In particular, I'm currently looking at the run-ruby function right now.

I decided that aliasing bundle to run under the ssh box would do this, so I made myself an eshell alias, but that doesn't seem to get loaded in comint-mode, which I'm fairly certain is how such commands are run.

Another approach might be to have a comint hook which first SSH's into the box before running another command.

Is this possible? Any other suggestions?


I added the docker tag to this because the workflow can be quite similar, and there's no existing vagrant tag.

  • As for docker: I have a bash script that I set as an executable which is run by shell command. The script does roughly docker exec -ti some_container bash, which then runs interactive shell inside the container. – wvxvw Aug 12 '16 at 7:42

I use next function to run rails console on remote host.

It seems that run-ruby doesn't care how REPL is started, so I pass it an ssh command. Most important part is the command itself:

  • -t for pseudo-terminal mode, without it repl won't work;
  • bash --login to get usual shell (for rbenv, rvm or other stuff that initialised on shell startup). If you use zsh, you can share init code somewhere in .profile and add source $HOME/.profile to both: .zshrc and .bashrc ;
  • -c is a bash option with command to run in single quotes

Also there are cd to set working directory and for my case - environment type (production, testing, etc..)

(defun rails-console-remote (&optional host &optional path &optional env &optional user-cmd)
  "Call `run-ruby'."
  (interactive "P")
  (let ((default-cmd '"bundle exec rails console"))
     (format "/usr/bin/ssh -t %s cd %s; /bin/bash --login -c '%s %s'"
             (or host (read-string "host: "))
             (or path (read-string "path: "))
             (if user-cmd
               (read-string "rails console: " default-cmd))
             (or env "production")))))

P.S.: &optional and (or var (read-string "prompt: ")) to make it more interactive.

  • Could you explain your answer in more detail? – Dan Feb 15 '17 at 15:24

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.