summaryrefslogtreecommitdiff
path: root/multishell.el
diff options
context:
space:
mode:
authorKen Manheimer <ken.manheimer@gmail.com>2016-06-27 13:11:34 -0400
committerKen Manheimer <ken.manheimer@gmail.com>2016-06-27 13:11:34 -0400
commitb314574252f9c42833c48ad822b31ce51e01bc20 (patch)
tree8d43ffd3f57602830561fd107c283c7a2510661c /multishell.el
parente6eade0542bcbb262816a10aa183165cab34bdfb (diff)
multishell-start-shell-in-buffer: be tolerant of absent remote dirs.xo
If cd fails to an included remote directory, try again without the cd.
Diffstat (limited to 'multishell.el')
-rw-r--r--multishell.el27
1 files changed, 24 insertions, 3 deletions
diff --git a/multishell.el b/multishell.el
index 51bad08..23da6ae 100644
--- a/multishell.el
+++ b/multishell.el
@@ -694,7 +694,11 @@ and path nil if none is resolved."
(declare-function tramp-cleanup-connection "tramp")
(defun multishell-start-shell-in-buffer (path)
- "Start, restart, or continue a shell in BUFFER-NAME on PATH."
+ "Start, restart, or continue a shell in BUFFER-NAME on PATH.
+
+If the path is remote and includes a directory, cd to that directory on the remote path.
+
+If cd fails to an included remote directory, try again without the cd."
(let* ((is-active (comint-check-proc (current-buffer))))
(when (and path (not is-active))
@@ -710,8 +714,25 @@ and path nil if none is resolved."
(tramp-dissect-file-name default-directory 'noexpand)
'keep-debug 'keep-password))
- (when (file-remote-p path) (message "Connecting to %s" path))
- (cd path))
+ (if (not (file-remote-p path))
+ (cd path)
+ (message "Connecting to %s" path)
+ (condition-case err
+ (cd path)
+ ;; "cd: No such directory found via CDPATH environment variable"
+ (error
+ (if (string=
+ (cadr err)
+ "No such directory found via CDPATH environment variable")
+ ;; Try again without dir part of remote path:
+ (let* ((final-colon-at (string-match ":[^:]+$" path))
+ (sans-dir-path (substring path 0 (1+ final-colon-at)))
+ (dir-path (substring path (1+ final-colon-at))))
+ (message "Failed to cd to %s, trying again without..."
+ dir-path)
+ (sit-for .5)
+ (cd sans-dir-path))
+ (signal (car err) (cdr err)))))))
(shell (current-buffer))))