+(defun multishell-derive-target-name-and-path (path-ish)
+ "Give tramp-style PATH-ISH, determine target name and default directory.
+
+The name is the part of the string before the initial '/' slash,
+if any. Otherwise, it's either the host-name, domain-name, final
+directory name, or local host name. The path is everything
+besides the string before the initial '/' slash.
+
+Return them as a list (name dir), with dir nil if none given."
+ (let (name (path "") dir)
+ (cond ((string= path-ish "") (setq dir multishell-primary-name))
+ ((string-match "^\\*\\([^/]*\\)\\(/.*/\\)\\(.*\\)\\*" path-ish)
+ ;; We have a path, use it
+ (let ((overt-name (match-string 1 path-ish))
+ (overt-path (match-string 2 path-ish))
+ (trailing-name (match-string 3 path-ish)))
+ (if (string= overt-name "") (setq overt-name nil))
+ (if (string= overt-path "") (setq overt-path nil))
+ (if (string= trailing-name "") (setq trailing-name nil))
+ (setq path (concat overt-path trailing-name))
+ (setq name
+ (multishell-bracket-asterisks
+ (or overt-name
+ (if (file-remote-p path)
+ (let ((vec (tramp-dissect-file-name path)))
+ (or (tramp-file-name-host vec)
+ (tramp-file-name-domain vec)
+ (tramp-file-name-localname vec)
+ trailing-name
+ system-name))
+ (multishell-unbracket-asterisks
+ multishell-primary-name)))))))
+ (t (setq name (multishell-bracket-asterisks path-ish))))
+ (list name path)))