Skip to content

Instantly share code, notes, and snippets.

@dfeich
Last active November 23, 2018 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dfeich/50ee86c3d4338dbc878b to your computer and use it in GitHub Desktop.
Save dfeich/50ee86c3d4338dbc878b to your computer and use it in GitHub Desktop.
Emacs function to open a gnome-terminal at location of default-directory (handles remote locations)
(defun dfeich/gnome-terminal (&optional path)
"Opens a gnome terminal at PATH. If no PATH is given, it uses
the value of `default-directory'. PATH may be a tramp remote path."
(interactive)
(unless path (setq path default-directory))
(if (tramp-tramp-file-p path)
(let ((tstruct (tramp-dissect-file-name path)))
(cond
((equal (tramp-file-name-method tstruct) "ssh")
(call-process "/usr/bin/gnome-terminal" nil nil nil
"--" "bash" "-c"
(format "ssh -t %s 'cd %s; exec bash'; exec bash"
(tramp-file-name-host tstruct)
(tramp-file-name-localname tstruct))))
(t (error "not implemented for method%s"
(tramp-file-name-method tstruct)))))
(call-process "/usr/bin/gnome-terminal" nil nil nil
"--" "bash" "-c"
(format "cd %s;exec bash" path))))
@dfeich
Copy link
Author

dfeich commented Nov 23, 2018

In Ubuntu 18.04 with gnome-terminal 3.28.2-1ubuntu1~18 I had to adapt to the fact that the "-x" flag to gnome-terminal is becoming obsolete. Can be replaced by "--" to indicate to gnome-terminal that the following sequence is a command and should not be parsed by gnome-terminal as an option containing string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment