Skip to content

Instantly share code, notes, and snippets.

@DanielG
Created March 9, 2018 15:31
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 DanielG/344f8c549e7dca35969909ea6330b1c2 to your computer and use it in GitHub Desktop.
Save DanielG/344f8c549e7dca35969909ea6330b1c2 to your computer and use it in GitHub Desktop.
;; Open terminal in current default-directory
(require 'cl)
;; returns '(method user host path)
(defun dxld-parse-tramp-path (path)
(with-temp-buffer
(insert path)
(goto-char (point-min))
(if (condition-case nil
(re-search-forward "^/\\(?:\\([^:@]+\\):\\)?\\(?:\\([^:@]+\\)@\\)?\\([^:@]+\\):\\([^:@]+\\)?")
(error nil))
(loop for i from 1 to 4
collect (match-string i)))))
(defun dxld-tramp-path (p)
(nth 3 (dxld-parse-tramp-path p)))
(defun dxld-tramp-host (p)
(nth 2 (dxld-parse-tramp-path p)))
(defun dxld-tramp-normalize-path (path)
(if (string-match "^/\\|^~" path)
path
(concat "~/" path)))
(defun dxld-open-terminal (&optional dir)
"Open a terminal in the specified directory DIR or in
default-directory if nil."
(interactive)
(let ((default-directory (or dir default-directory))
(path (dxld-tramp-path default-directory))
(host (dxld-tramp-host default-directory)))
(if path
(call-process "urxvt" nil 0 nil "-e"
"ssh" "-t" host (format "cd %s; exec $SHELL" path))
(call-process "urxvt" nil 0))))
(provide 'open-term)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment