Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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."
(unless path (setq path default-directory))
(if (tramp-tramp-file-p path)
(let ((tstruct (tramp-dissect-file-name path)))
((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))))

This comment has been minimized.

Copy link
Owner Author

@dfeich 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