masasam/emacs-counsel-tramp

Provide default directory to open on remote

Closed this issue · 2 comments

I ssh to different remote machines, and the work directory is sometimes different from the home directory that tramp logs in to. Is it possible to make counsel-tramp open a custom default directory when I login to a machine A?

For example, default directory on Machine A is /users/swarnendu and default directory on Machine B is /data/swarnendu.

Hi @swarnendubiswas .
Thank you for comment.

There is a problem doing it with the counsel-tramp itself.
It is recommended to do the following.

write this at your init.el or .emacs.

(defun yoursshlist ()
  (let (hosts)
    (push
     (concat "/ssh:yoursite:/users/swarnendu")
     hosts)
    (push
     (concat "/ssh:yoursite2:/data/swarnendu")
     hosts)))

(defun your-counsel-tramp ()
  (interactive)
  (counsel-find-file (ivy-read "Tramp: " (yoursshlist))))

Then run M-x your-counsel-tramp on your Emacs.

Thanks, that works.