Created
March 9, 2018 15:31
-
-
Save DanielG/344f8c549e7dca35969909ea6330b1c2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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