summaryrefslogtreecommitdiff
path: root/terminal-here.el
diff options
context:
space:
mode:
authorDavid Shepherd <davidshepherd7@gmail.com>2017-10-22 13:52:34 +0100
committerDavid Shepherd <davidshepherd7@gmail.com>2017-10-22 13:52:34 +0100
commitb3659e13d3d41503b4fc59dd2c7ea622631fc3ec (patch)
treed9a09fba071e56c6161a324e904b9a9a3dd0fc9f /terminal-here.el
parentUpdate .travis.yml (diff)
downloademacs-terminal-here-b3659e13d3d41503b4fc59dd2c7ea622631fc3ec.tar.gz
Add support for file paths opened using tramp and sudo
Fixes #7.
Diffstat (limited to 'terminal-here.el')
-rw-r--r--terminal-here.el32
1 files changed, 31 insertions, 1 deletions
diff --git a/terminal-here.el b/terminal-here.el
index 1af5d37..4dc8cef 100644
--- a/terminal-here.el
+++ b/terminal-here.el
@@ -18,6 +18,11 @@
;;; Code:
(require 'cl-lib)
+
+;; TODO: it would be nice not to need to load all of tramp just for the file
+;; name parsing. I'm not sure if that's possible though.
+(require 'tramp)
+
(defgroup terminal-here nil
@@ -65,7 +70,31 @@ buffer is not in a project."
(defun terminal-here-launch-in-directory (dir)
- "Launch a terminal in directory DIR."
+ "Launch a terminal in directory DIR.
+
+Handles tramp paths sensibly."
+ (terminal-here--do-launch (or (terminal-here-maybe-tramp-path-to-directory dir)
+ dir)))
+
+
+(defun terminal-here-maybe-tramp-path-to-directory (dir)
+ "Extract the local part of a local tramp path.
+
+Given a tramp path returns the local part, otherwise returns nil."
+ (when (tramp-tramp-file-p dir)
+ (let ((file-name-struct (tramp-dissect-file-name dir)))
+ (cond
+ ((equal (tramp-file-name-method file-name-struct) "sudo")
+ (tramp-file-name-localname file-name-struct))
+ (t (user-error "Terminal here cannot currently handle tramp files other than sudo"))))))
+
+
+(defun terminal-here--do-launch (dir)
+ "Internal function to launch the terminal in directory DIR.
+
+For launching a terminal from emacs lisp you almost almost
+certainly want to call `terminal-here-launch-in-directory' which
+also handles tramp mappings."
(let* ((term-command (if (functionp terminal-here-terminal-command)
(funcall terminal-here-terminal-command dir)
terminal-here-terminal-command))
@@ -82,6 +111,7 @@ buffer is not in a project."
;; Don't close when emacs closes, seems to only be necessary on Windows.
(set-process-query-on-exit-flag proc nil)))
+
;;;###autoload
(defun terminal-here-launch ()
"Launch a terminal in the current working directory.