]> code.delx.au - gnu-emacs/blobdiff - lisp/eshell/em-unix.el
Merge from trunk.
[gnu-emacs] / lisp / eshell / em-unix.el
index 365f765433be3fc691093d7d1be00187c756871d..32744c702a6d3c51dc7f58f738564896db548ef4 100644 (file)
@@ -1,7 +1,6 @@
 ;;; em-unix.el --- UNIX command aliases
 
-;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
-;;   2008, 2009, 2010  Free Software Foundation, Inc.
+;; Copyright (C) 1999-2012 Free Software Foundation, Inc.
 
 ;; Author: John Wiegley <johnw@gnu.org>
 
@@ -41,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
@@ -52,10 +52,11 @@ 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 '(eshell-unix-initialize)
+(defcustom eshell-unix-load-hook nil
   "A list of functions to run when `eshell-unix' is loaded."
+  :version "24.1"                      ; removed eshell-unix-initialize
   :type 'hook
   :group 'eshell-unix)
 
@@ -154,10 +155,10 @@ Otherwise, Emacs will attempt to use rsh to invoke du on the remote machine."
 (defalias 'eshell/basename 'file-name-nondirectory)
 (defalias 'eshell/dirname  'file-name-directory)
 
-(defvar interactive)
-(defvar preview)
-(defvar recursive)
-(defvar verbose)
+(defvar em-interactive)
+(defvar em-preview)
+(defvar em-recursive)
+(defvar em-verbose)
 
 (defun eshell/man (&rest args)
   "Invoke man, flattening the arguments appropriately."
@@ -204,21 +205,21 @@ Otherwise, Emacs will attempt to use rsh to invoke du on the remote machine."
       (if (and (file-directory-p (car files))
               (not (file-symlink-p (car files))))
          (progn
-           (if verbose
+           (if em-verbose
                (eshell-printn (format "rm: removing directory `%s'"
                                       (car files))))
            (unless
-               (or preview
-                   (and interactive
+               (or em-preview
+                   (and em-interactive
                         (not (y-or-n-p
                               (format "rm: remove directory `%s'? "
                                       (car files))))))
              (eshell-funcalln 'delete-directory (car files) t t)))
-       (if verbose
+       (if em-verbose
            (eshell-printn (format "rm: removing file `%s'"
                                   (car files))))
-       (unless (or preview
-                   (and interactive
+       (unless (or em-preview
+                   (and em-interactive
                         (not (y-or-n-p
                               (format "rm: remove `%s'? "
                                       (car files))))))
@@ -235,21 +236,21 @@ argument."
    "rm" args
    '((?h "help" nil nil "show this usage screen")
      (?f "force" nil force-removal "force removal")
-     (?i "interactive" nil interactive "prompt before any removal")
-     (?n "preview" nil preview "don't change anything on disk")
-     (?r "recursive" nil recursive
+     (?i "interactive" nil em-interactive "prompt before any removal")
+     (?n "preview" nil em-preview "don't change anything on disk")
+     (?r "recursive" nil em-recursive
         "remove the contents of directories recursively")
-     (?R nil nil recursive "(same)")
-     (?v "verbose" nil verbose "explain what is being done")
+     (?R nil nil em-recursive "(same)")
+     (?v "verbose" nil em-verbose "explain what is being done")
      :preserve-args
      :external "rm"
      :show-usage
      :usage "[OPTION]... FILE...
 Remove (unlink) the FILE(s).")
-   (unless interactive
-     (setq interactive eshell-rm-interactive-query))
-   (if (and force-removal interactive)
-       (setq interactive nil))
+   (unless em-interactive
+     (setq em-interactive eshell-rm-interactive-query))
+   (if (and force-removal em-interactive)
+       (setq em-interactive nil))
    (while args
      (let ((entry (if (stringp (car args))
                      (directory-file-name (car args))
@@ -258,37 +259,37 @@ Remove (unlink) the FILE(s).")
                      (car args)))))
        (cond
        ((bufferp entry)
-        (if verbose
+        (if em-verbose
             (eshell-printn (format "rm: removing buffer `%s'" entry)))
-        (unless (or preview
-                    (and interactive
+        (unless (or em-preview
+                    (and em-interactive
                          (not (y-or-n-p (format "rm: delete buffer `%s'? "
                                                 entry)))))
           (eshell-funcalln 'kill-buffer entry)))
        ((eshell-processp entry)
-        (if verbose
+        (if em-verbose
             (eshell-printn (format "rm: killing process `%s'" entry)))
-        (unless (or preview
-                    (and interactive
+        (unless (or em-preview
+                    (and em-interactive
                          (not (y-or-n-p (format "rm: kill process `%s'? "
                                                 entry)))))
           (eshell-funcalln 'kill-process entry)))
        ((symbolp entry)
-        (if verbose
+        (if em-verbose
             (eshell-printn (format "rm: uninterning symbol `%s'" entry)))
         (unless
-            (or preview
-                (and interactive
+            (or em-preview
+                (and em-interactive
                      (not (y-or-n-p (format "rm: unintern symbol `%s'? "
                                             entry)))))
           (eshell-funcalln 'unintern entry)))
        ((stringp entry)
         (if (and (file-directory-p entry)
                  (not (file-symlink-p entry)))
-            (if (or recursive
+            (if (or em-recursive
                     eshell-rm-removes-directories)
-                (if (or preview
-                        (not interactive)
+                (if (or em-preview
+                        (not em-interactive)
                         (y-or-n-p
                          (format "rm: descend into directory `%s'? "
                                  entry)))
@@ -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))
 
@@ -333,8 +335,6 @@ Remove the DIRECTORY(ies), if they are empty.")
 (put 'eshell/rmdir 'eshell-no-numeric-conversions t)
 
 (defvar no-dereference)
-(defvar preview)
-(defvar verbose)
 
 (defvar eshell-warn-dot-directories t)
 
@@ -342,9 +342,9 @@ Remove the DIRECTORY(ies), if they are empty.")
   "Shuffle around some filesystem entries, using FUNC to do the work."
   (let ((attr-target (eshell-file-attributes target))
        (is-dir (or (file-directory-p target)
-                   (and preview (not eshell-warn-dot-directories))))
+                   (and em-preview (not eshell-warn-dot-directories))))
        attr)
-    (if (and (not preview) (not is-dir)
+    (if (and (not em-preview) (not is-dir)
             (> (length files) 1))
        (error "%s: when %s multiple files, last argument must be a directory"
               command action))
@@ -381,7 +381,7 @@ Remove the DIRECTORY(ies), if they are empty.")
                   (not (memq func '(make-symbolic-link
                                     add-name-to-file))))
              (if (and (eq func 'copy-file)
-                      (not recursive))
+                      (not em-recursive))
                  (eshell-error (format "%s: %s: omitting directory\n"
                                        command (car files)))
                (let (eshell-warn-dot-directories)
@@ -399,11 +399,11 @@ Remove the DIRECTORY(ies), if they are empty.")
                                             (expand-file-name target)))))))
                      (apply 'eshell-funcalln func source target args)
                  (unless (file-directory-p target)
-                   (if verbose
+                   (if em-verbose
                        (eshell-printn
                         (format "%s: making directory %s"
                                 command target)))
-                   (unless preview
+                   (unless em-preview
                      (eshell-funcalln 'make-directory target)))
                  (apply 'eshell-shuffle-files
                         command action
@@ -414,16 +414,16 @@ Remove the DIRECTORY(ies), if they are empty.")
                          (directory-files source))
                         target func t args)
                  (when (eq func 'rename-file)
-                   (if verbose
+                   (if em-verbose
                        (eshell-printn
                         (format "%s: deleting directory %s"
                                 command source)))
-                   (unless preview
+                   (unless em-preview
                      (eshell-funcalln 'delete-directory source))))))
-           (if verbose
+           (if em-verbose
                (eshell-printn (format "%s: %s -> %s" command
                                       source target)))
-           (unless preview
+           (unless em-preview
              (if (and no-dereference
                       (setq link (file-symlink-p source)))
                  (progn
@@ -448,7 +448,7 @@ Remove the DIRECTORY(ies), if they are empty.")
     (if (file-exists-p archive)
        (setq tar-args (concat "u" tar-args))
       (setq tar-args (concat "c" tar-args)))
-    (if verbose
+    (if em-verbose
        (setq tar-args (concat "v" tar-args)))
     (if (equal command "mv")
        (setq tar-args (concat "--remove-files -" tar-args)))
@@ -481,7 +481,7 @@ Remove the DIRECTORY(ies), if they are empty.")
         (eshell-shuffle-files
          ,command ,action args target ,func nil
          ,@(append
-            `((if (and (or interactive
+            `((if (and (or em-interactive
                            ,query-var)
                        (not force))
                   1 (or force ,force-var)))
@@ -495,11 +495,11 @@ Remove the DIRECTORY(ies), if they are empty.")
    "mv" args
    '((?f "force" nil force
         "remove existing destinations, never prompt")
-     (?i "interactive" nil interactive
+     (?i "interactive" nil em-interactive
         "request confirmation if target already exists")
-     (?n "preview" nil preview
+     (?n "preview" nil em-preview
         "don't change anything on disk")
-     (?v "verbose" nil verbose
+     (?v "verbose" nil em-verbose
         "explain what is being done")
      (nil "help" nil nil "show this usage screen")
      :preserve-args
@@ -526,15 +526,15 @@ Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.
         "preserve links")
      (?f "force" nil force
         "remove existing destinations, never prompt")
-     (?i "interactive" nil interactive
+     (?i "interactive" nil em-interactive
         "request confirmation if target already exists")
-     (?n "preview" nil preview
+     (?n "preview" nil em-preview
         "don't change anything on disk")
      (?p "preserve" nil preserve
         "preserve file attributes if possible")
-     (?R "recursive" nil recursive
+     (?R "recursive" nil em-recursive
         "copy directories recursively")
-     (?v "verbose" nil verbose
+     (?v "verbose" nil em-verbose
         "explain what is being done")
      (nil "help" nil nil "show this usage screen")
      :preserve-args
@@ -544,7 +544,7 @@ Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.
    or:  cp [OPTION]... SOURCE... DIRECTORY
 Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.")
    (if archive
-       (setq preserve t no-dereference t recursive t))
+       (setq preserve t no-dereference t em-recursive t))
    (eshell-mvcpln-template "cp" "copying" 'copy-file
                           eshell-cp-interactive-query
                           eshell-cp-overwrite-files preserve)))
@@ -558,12 +558,12 @@ Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.")
    '((?h "help" nil nil "show this usage screen")
      (?s "symbolic" nil symbolic
         "make symbolic links instead of hard links")
-     (?i "interactive" nil interactive
+     (?i "interactive" nil em-interactive
         "request confirmation if target already exists")
      (?f "force" nil force "remove existing destinations, never prompt")
-     (?n "preview" nil preview
+     (?n "preview" nil em-preview
         "don't change anything on disk")
-     (?v "verbose" nil verbose "explain what is being done")
+     (?v "verbose" nil em-verbose "explain what is being done")
      :preserve-args
      :external "ln"
      :show-usage
@@ -590,7 +590,7 @@ symlink, then revert to the system's definition of cat."
   (setq args (eshell-stringify-list (eshell-flatten-list args)))
   (if (or eshell-in-pipeline-p
          (catch 'special
-           (eshell-for arg args
+           (dolist (arg args)
              (unless (or (and (stringp arg)
                               (> (length arg) 0)
                               (eq (aref arg 0) ?-))
@@ -601,7 +601,7 @@ symlink, then revert to the system's definition of cat."
       (let ((ext-cat (eshell-search-path "cat")))
        (if ext-cat
            (throw 'eshell-replace-command
-                  (eshell-parse-command ext-cat args))
+                  (eshell-parse-command (eshell-quote-argument ext-cat) args))
          (if eshell-in-pipeline-p
              (error "Eshell's `cat' does not work in pipelines")
            (error "Eshell's `cat' cannot display one of the files given"))))
@@ -613,12 +613,12 @@ symlink, then revert to the system's definition of cat."
        :show-usage
        :usage "[OPTION] FILE...
 Concatenate FILE(s), or standard input, to standard output.")
-     (eshell-for file args
+     (dolist (file args)
        (if (string= file "-")
           (throw 'eshell-external
                  (eshell-external-command "cat" args))))
      (let ((curbuf (current-buffer)))
-       (eshell-for file args
+       (dolist (file args)
         (with-temp-buffer
           (insert-file-contents file)
           (goto-char (point-min))
@@ -714,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)
@@ -794,8 +794,6 @@ external command."
   (funcall (or (pcomplete-find-completion-function (pcomplete-arg 1))
               pcomplete-default-completion-function)))
 
-(defalias 'pcomplete/ssh 'pcomplete/rsh)
-
 (defvar block-size)
 (defvar by-bytes)
 (defvar dereference-links)
@@ -854,12 +852,12 @@ external command."
   (let ((ext-du (eshell-search-path "du")))
     (if (and ext-du
             (not (catch 'have-ange-path
-                   (eshell-for arg args
+                   (dolist (arg args)
                      (if (string-equal
                           (file-remote-p (expand-file-name arg) 'method) "ftp")
                          (throw 'have-ange-path t))))))
        (throw 'eshell-replace-command
-              (eshell-parse-command ext-du args))
+              (eshell-parse-command (eshell-quote-argument ext-du) args))
       (eshell-eval-using-options
        "du" args
        '((?a "all" nil show-all
@@ -914,9 +912,7 @@ Summarize disk usage of each FILE, recursively for directories.")
 (defvar eshell-time-start nil)
 
 (defun eshell-show-elapsed-time ()
-  (let ((elapsed (format "%.3f secs\n"
-                        (- (eshell-time-to-seconds (current-time))
-                           eshell-time-start))))
+  (let ((elapsed (format "%.3f secs\n" (- (float-time) eshell-time-start))))
     (set-text-properties 0 (length elapsed) '(face bold) elapsed)
     (eshell-interactive-print elapsed))
   (remove-hook 'eshell-post-command-hook 'eshell-show-elapsed-time t))
@@ -942,7 +938,7 @@ Summarize disk usage of each FILE, recursively for directories.")
        :show-usage
        :usage "COMMAND...
 Show wall-clock time elapsed during execution of COMMAND.")
-     (setq eshell-time-start (eshell-time-to-seconds (current-time)))
+     (setq eshell-time-start (float-time))
      (add-hook 'eshell-post-command-hook 'eshell-show-elapsed-time nil t)
      ;; after setting
      (throw 'eshell-replace-command
@@ -969,6 +965,8 @@ Show wall-clock time elapsed during execution of COMMAND.")
     ((string-match "[^[:blank:]]" string) string)
     (nil)))
 
+(autoload 'diff-no-select "diff")
+
 (defun eshell/diff (&rest args)
   "Alias \"diff\" to call Emacs `diff' function."
   (let ((orig-args (eshell-stringify-list (eshell-flatten-list args))))
@@ -990,8 +988,9 @@ Show wall-clock time elapsed during execution of COMMAND.")
          (setcdr (last args 3) nil))
        (with-current-buffer
            (condition-case err
-               (diff old new
-                     (nil-blank-string (eshell-flatten-and-stringify args)))
+               (diff-no-select
+                old new
+                (nil-blank-string (eshell-flatten-and-stringify args)))
              (error
               (throw 'eshell-replace-command
                      (eshell-parse-command "*diff" orig-args))))
@@ -1039,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
@@ -1059,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))))
-             (eshell-for arg args
+                          (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
@@ -1096,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)
@@ -1121,5 +1123,4 @@ Execute a COMMAND as the superuser or another USER.")
 ;; generated-autoload-file: "esh-groups.el"
 ;; End:
 
-;; arch-tag: 2462edd2-a76a-4cf2-897d-92e9a82ac1c9
 ;;; em-unix.el ends here