]> code.delx.au - gnu-emacs/blobdiff - lisp/eshell/em-unix.el
Merge from emacs-24; up to 2012-12-06T01:39:03Z!monnier@iro.umontreal.ca
[gnu-emacs] / lisp / eshell / em-unix.el
index 6ac53e30e86862b35123f8e4d8c7f889782a60d9..f6dd0d5e990ab00c71a1fc22f92826603beeb877 100644 (file)
@@ -1,6 +1,6 @@
 ;;; em-unix.el --- UNIX command aliases
 
-;; Copyright (C) 1999-201 Free Software Foundation, Inc.
+;; Copyright (C) 1999-2013 Free Software Foundation, Inc.
 
 ;; Author: John Wiegley <johnw@gnu.org>
 
@@ -40,7 +40,8 @@
 (require 'pcomplete)
 
 ;;;###autoload
-(eshell-defgroup eshell-unix nil
+(progn
+(defgroup eshell-unix nil
   "This module defines many of the more common UNIX utilities as
 aliases implemented in Lisp.  These include mv, ln, cp, rm, etc.  If
 the user passes arguments which are too complex, or are unrecognized
@@ -51,7 +52,7 @@ with Eshell makes them more versatile than their traditional cousins
 \(such as being able to use `kill' to kill Eshell background processes
 by name)."
   :tag "UNIX commands in Lisp"
-  :group 'eshell-module)
+  :group 'eshell-module))
 
 (defcustom eshell-unix-load-hook nil
   "A list of functions to run when `eshell-unix' is loaded."
@@ -305,12 +306,13 @@ Remove (unlink) the FILE(s).")
   (eshell-eval-using-options
    "mkdir" args
    '((?h "help" nil nil "show this usage screen")
+     (?p "parents" nil em-parents "make parent directories as needed")
      :external "mkdir"
      :show-usage
      :usage "[OPTION] DIRECTORY...
 Create the DIRECTORY(ies), if they do not already exist.")
    (while args
-     (eshell-funcalln 'make-directory (car args))
+     (eshell-funcalln 'make-directory (car args) em-parents)
      (setq args (cdr args)))
    nil))
 
@@ -712,7 +714,7 @@ available..."
 
 (defun eshell-grep (command args &optional maybe-use-occur)
   "Generic service function for the various grep aliases.
-It calls Emacs' grep utility if the command is not redirecting output,
+It calls Emacs's grep utility if the command is not redirecting output,
 and if it's not part of a command pipeline.  Otherwise, it calls the
 external command."
   (if (and maybe-use-occur eshell-no-grep-available)
@@ -1036,12 +1038,8 @@ Show wall-clock time elapsed during execution of COMMAND.")
 
 (put 'eshell/occur 'eshell-no-numeric-conversions t)
 
-;; Pacify the byte-compiler.
-(defvar tramp-default-proxies-alist)
-
 (defun eshell/su (&rest args)
   "Alias \"su\" to call Tramp."
-  (require 'tramp)
   (setq args (eshell-stringify-list (eshell-flatten-list args)))
   (let ((orig-args (copy-tree args)))
     (eshell-eval-using-options
@@ -1056,29 +1054,29 @@ Become another USER during a login session.")
                  (host (or (file-remote-p default-directory 'host)
                            "localhost"))
                  (dir (or (file-remote-p default-directory 'localname)
-                          (expand-file-name default-directory))))
+                          (expand-file-name default-directory)))
+                 (prefix (file-remote-p default-directory)))
              (dolist (arg args)
                (if (string-equal arg "-") (setq login t) (setq user arg)))
              ;; `eshell-eval-using-options' does not handle "-".
              (if (member "-" orig-args) (setq login t))
              (if login (setq dir "~/"))
-             (if (and (file-remote-p default-directory)
+             (if (and prefix
                       (or
                        (not (string-equal
                              "su" (file-remote-p default-directory 'method)))
                        (not (string-equal
                              user (file-remote-p default-directory 'user)))))
-                 (add-to-list
-                  'tramp-default-proxies-alist
-                  (list host user (file-remote-p default-directory))))
-             (eshell-parse-command
-              "cd" (list (format "/su:%s@%s:%s" user host dir))))))))
+                 (eshell-parse-command
+                  "cd" (list (format "%s|su:%s@%s:%s"
+                                     (substring prefix 0 -1) user host dir)))
+               (eshell-parse-command
+                "cd" (list (format "/su:%s@%s:%s" user host dir)))))))))
 
 (put 'eshell/su 'eshell-no-numeric-conversions t)
 
 (defun eshell/sudo (&rest args)
   "Alias \"sudo\" to call Tramp."
-  (require 'tramp)
   (setq args (eshell-stringify-list (eshell-flatten-list args)))
   (let ((orig-args (copy-tree args)))
     (eshell-eval-using-options
@@ -1093,21 +1091,28 @@ Execute a COMMAND as the superuser or another USER.")
                  (host (or (file-remote-p default-directory 'host)
                            "localhost"))
                  (dir (or (file-remote-p default-directory 'localname)
-                          (expand-file-name default-directory))))
+                          (expand-file-name default-directory)))
+                 (prefix (file-remote-p default-directory)))
              ;; `eshell-eval-using-options' reads options of COMMAND.
              (while (and (stringp (car orig-args))
                          (member (car orig-args) '("-u" "--user")))
                (setq orig-args (cddr orig-args)))
-             (if (and (file-remote-p default-directory)
-                      (or
-                       (not (string-equal
-                             "sudo" (file-remote-p default-directory 'method)))
-                       (not (string-equal
-                             user (file-remote-p default-directory 'user)))))
-                 (add-to-list
-                  'tramp-default-proxies-alist
-                  (list host user (file-remote-p default-directory))))
-             (let ((default-directory (format "/sudo:%s@%s:%s" user host dir)))
+             (let ((default-directory
+                     (if (and prefix
+                              (or
+                               (not
+                                (string-equal
+                                 "sudo"
+                                 (file-remote-p default-directory 'method)))
+                               (not
+                                (string-equal
+                                 user
+                                 (file-remote-p default-directory 'user)))))
+                         (format "%s|sudo:%s@%s:%s"
+                                 (substring prefix 0 -1) user host dir)
+                       (format "/sudo:%s@%s:%s" user host dir))))
+               ;; Ensure, that Tramp has connected to that construct already.
+               (ignore (file-exists-p default-directory))
                (eshell-named-command (car orig-args) (cdr orig-args))))))))
 
 (put 'eshell/sudo 'eshell-no-numeric-conversions t)