1

How to start Emacs from the command line with and open file trough ssh?

What I usually do is first open Emacs and do: C-X C-F /ssh:my_remote_server:/file.txt RET

How can I directly open the file from the command line doing something similar to:

emacs --remote "/ssh:my_remote_server:/file.txt"

ucsky
  • 133
  • 4
  • I guess this approach can help for you. https://emacs.stackexchange.com/questions/25033/run-elisp-from-command-line-in-running-emacs – itirazimvar Jan 17 '21 at 20:08
  • 1
    Doing `emacs -Q "/ssh:my_remote_server:/file.txt"` works fine for me. Where/how does it break for you? – NickD Jan 17 '21 at 20:52
  • @NickD yes that work, could you do an answer with this? – ucsky Jan 18 '21 at 08:27

1 Answers1

2

To open a file when starting a new instance of Emacs you can generally do:

emacs "/ssh:server:file"

as described in man emacs:

SYNOPSIS
       emacs [ command-line switches ] [ files ... ]

If you use Emacs daemon and want to open a file within an existing instance of Emacs you can do emacsclient "/ssh:server:file" as well but it will cause emacsclient to block the terminal:

$ emacsclient "/ssh:freebsd:Makefile"
Waiting for Emacs...

If you want to use emacsclient without blocking the terminal do:

emacsclient --eval "(with-current-buffer  (window-buffer) (find-file \"/ssh:server:file\"))"