annotate lisp/eshell/em-unix.el @ 39822:0c3ebbbc4922

*** empty log message ***
author Gerd Moellmann <gerd@gnu.org>
date Fri, 12 Oct 2001 10:05:27 +0000
parents 1e91a5f60ae6
children 3a906538d254
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38414
67b464da13ec Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 37661
diff changeset
1 ;;; em-unix.el --- UNIX command aliases
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
2
35588
31904bdf4350 See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 33020
diff changeset
3 ;; Copyright (C) 1999, 2000, 2001 Free Software Foundation
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
4
32526
8e57189d61b4 Add author information.
Gerd Moellmann <gerd@gnu.org>
parents: 32493
diff changeset
5 ;; Author: John Wiegley <johnw@gnu.org>
8e57189d61b4 Add author information.
Gerd Moellmann <gerd@gnu.org>
parents: 32493
diff changeset
6
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
7 ;; This file is part of GNU Emacs.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
8
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
10 ;; it under the terms of the GNU General Public License as published by
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
11 ;; the Free Software Foundation; either version 2, or (at your option)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
12 ;; any later version.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
13
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
14 ;; GNU Emacs is distributed in the hope that it will be useful,
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
17 ;; GNU General Public License for more details.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
18
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
22 ;; Boston, MA 02111-1307, USA.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
23
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
24 (provide 'em-unix)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
25
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
26 (eval-when-compile (require 'esh-maint))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
27
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
28 (defgroup eshell-unix nil
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
29 "This module defines many of the more common UNIX utilities as
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
30 aliases implemented in Lisp. These include mv, ln, cp, rm, etc. If
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
31 the user passes arguments which are too complex, or are unrecognized
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
32 by the Lisp variant, the external version will be called (if
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
33 available). The only reason not to use them would be because they are
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
34 usually much slower. But in several cases their tight integration
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
35 with Eshell makes them more versatile than their traditional cousins
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
36 \(such as being able to use `kill' to kill Eshell background processes
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
37 by name)."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
38 :tag "UNIX commands in Lisp"
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
39 :group 'eshell-module)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
40
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
41 ;;; Commentary:
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
42
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
43 ;; This file contains implementations of several UNIX command in Emacs
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
44 ;; Lisp, for several reasons:
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
45 ;;
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
46 ;; 1) it makes them available on all platforms where the Lisp
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
47 ;; functions used are available
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
48 ;;
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
49 ;; 2) it makes their functionality accessible and modified by the
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
50 ;; Lisp programmer.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
51 ;;
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
52 ;; 3) it allows Eshell to refrain from having to invoke external
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
53 ;; processes for common operations.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
54
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
55 (defcustom eshell-unix-load-hook '(eshell-unix-initialize)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
56 "*A list of functions to run when `eshell-unix' is loaded."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
57 :type 'hook
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
58 :group 'eshell-unix)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
59
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
60 (defcustom eshell-plain-grep-behavior nil
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
61 "*If non-nil, standalone \"grep\" commands will behave normally.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
62 Standalone in this context means not redirected, and not on the
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
63 receiving side of a command pipeline."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
64 :type 'boolean
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
65 :group 'eshell-unix)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
66
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
67 (defcustom eshell-no-grep-available (not (eshell-search-path "grep"))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
68 "*If non-nil, no grep is available on the current machine."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
69 :type 'boolean
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
70 :group 'eshell-unix)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
71
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
72 (defcustom eshell-plain-diff-behavior nil
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
73 "*If non-nil, standalone \"diff\" commands will behave normally.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
74 Standalone in this context means not redirected, and not on the
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
75 receiving side of a command pipeline."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
76 :type 'boolean
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
77 :group 'eshell-unix)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
78
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
79 (defcustom eshell-plain-locate-behavior nil
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
80 "*If non-nil, standalone \"locate\" commands will behave normally.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
81 Standalone in this context means not redirected, and not on the
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
82 receiving side of a command pipeline."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
83 :type 'boolean
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
84 :group 'eshell-unix)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
85
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
86 (defcustom eshell-rm-removes-directories nil
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
87 "*If non-nil, `rm' will remove directory entries.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
88 Otherwise, `rmdir' is required."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
89 :type 'boolean
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
90 :group 'eshell-unix)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
91
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
92 (defcustom eshell-rm-interactive-query (= (user-uid) 0)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
93 "*If non-nil, `rm' will query before removing anything."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
94 :type 'boolean
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
95 :group 'eshell-unix)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
96
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
97 (defcustom eshell-mv-interactive-query (= (user-uid) 0)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
98 "*If non-nil, `mv' will query before overwriting anything."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
99 :type 'boolean
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
100 :group 'eshell-unix)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
101
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
102 (defcustom eshell-mv-overwrite-files t
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
103 "*If non-nil, `mv' will overwrite files without warning."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
104 :type 'boolean
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
105 :group 'eshell-unix)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
106
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
107 (defcustom eshell-cp-interactive-query (= (user-uid) 0)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
108 "*If non-nil, `cp' will query before overwriting anything."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
109 :type 'boolean
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
110 :group 'eshell-unix)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
111
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
112 (defcustom eshell-cp-overwrite-files t
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
113 "*If non-nil, `cp' will overwrite files without warning."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
114 :type 'boolean
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
115 :group 'eshell-unix)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
116
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
117 (defcustom eshell-ln-interactive-query (= (user-uid) 0)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
118 "*If non-nil, `ln' will query before overwriting anything."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
119 :type 'boolean
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
120 :group 'eshell-unix)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
121
31241
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30269
diff changeset
122 (defcustom eshell-ln-overwrite-files nil
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
123 "*If non-nil, `ln' will overwrite files without warning."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
124 :type 'boolean
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
125 :group 'eshell-unix)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
126
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
127 (defcustom eshell-default-target-is-dot nil
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
128 "*If non-nil, the default destination for cp, mv or ln is `.'."
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
129 :type 'boolean
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
130 :group 'eshell-unix)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
131
32446
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
132 (defcustom eshell-du-prefer-over-ange nil
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
133 "*Use Eshell's du in ange-ftp remote directories.
32493
34d5d8707722 (eshell-du-prefer-over-ange): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents: 32446
diff changeset
134 Otherwise, Emacs will attempt to use rsh to invoke du on the remote machine."
32446
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
135 :type 'boolean
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
136 :group 'eshell-unix)
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
137
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
138 (require 'esh-opt)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
139
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
140 ;;; Functions:
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
141
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
142 (defun eshell-unix-initialize ()
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
143 "Initialize the UNIX support/emulation code."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
144 (make-local-hook 'eshell-post-command-hook)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
145 (when (eshell-using-module 'eshell-cmpl)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
146 (make-local-hook 'pcomplete-try-first-hook)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
147 (add-hook 'pcomplete-try-first-hook
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
148 'eshell-complete-host-reference nil t))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
149 (make-local-variable 'eshell-complex-commands)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
150 (setq eshell-complex-commands
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
151 (append '("grep" "egrep" "fgrep" "agrep" "glimpse" "locate"
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
152 "cat" "time" "cp" "mv" "make" "du" "diff")
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
153 eshell-complex-commands)))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
154
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
155 (defalias 'eshell/date 'current-time-string)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
156 (defalias 'eshell/basename 'file-name-nondirectory)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
157 (defalias 'eshell/dirname 'file-name-directory)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
158
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
159 (eval-when-compile
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
160 (defvar interactive)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
161 (defvar preview)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
162 (defvar recursive)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
163 (defvar verbose))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
164
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
165 (defun eshell/man (&rest args)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
166 "Invoke man, flattening the arguments appropriately."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
167 (funcall 'man (apply 'eshell-flatten-and-stringify args)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
168
37661
6d7c89c79996 Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents: 37655
diff changeset
169 (put 'eshell/man 'eshell-no-numeric-conversions t)
6d7c89c79996 Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents: 37655
diff changeset
170
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
171 (defun eshell-remove-entries (path files &optional top-level)
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
172 "From PATH, remove all of the given FILES, perhaps interactively."
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
173 (while files
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
174 (if (string-match "\\`\\.\\.?\\'"
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
175 (file-name-nondirectory (car files)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
176 (if top-level
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
177 (eshell-error "rm: cannot remove `.' or `..'\n"))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
178 (if (and (file-directory-p (car files))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
179 (not (file-symlink-p (car files))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
180 (let ((dir (file-name-as-directory (car files))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
181 (eshell-remove-entries dir
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
182 (mapcar
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
183 (function
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
184 (lambda (file)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
185 (concat dir file)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
186 (directory-files dir)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
187 (if verbose
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
188 (eshell-printn (format "rm: removing directory `%s'"
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
189 (car files))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
190 (unless
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
191 (or preview
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
192 (and interactive
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
193 (not (y-or-n-p
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
194 (format "rm: remove directory `%s'? "
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
195 (car files))))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
196 (eshell-funcalln 'delete-directory (car files))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
197 (if verbose
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
198 (eshell-printn (format "rm: removing file `%s'"
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
199 (car files))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
200 (unless (or preview
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
201 (and interactive
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
202 (not (y-or-n-p
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
203 (format "rm: remove `%s'? "
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
204 (car files))))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
205 (eshell-funcalln 'delete-file (car files)))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
206 (setq files (cdr files))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
207
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
208 (defun eshell/rm (&rest args)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
209 "Implementation of rm in Lisp.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
210 This is implemented to call either `delete-file', `kill-buffer',
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
211 `kill-process', or `unintern', depending on the nature of the
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
212 argument."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
213 (setq args (eshell-flatten-list args))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
214 (eshell-eval-using-options
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
215 "rm" args
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
216 '((?h "help" nil nil "show this usage screen")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
217 (?f "force" nil force-removal "force removal")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
218 (?i "interactive" nil interactive "prompt before any removal")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
219 (?n "preview" nil preview "don't change anything on disk")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
220 (?r "recursive" nil recursive
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
221 "remove the contents of directories recursively")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
222 (?R nil nil recursive "(same)")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
223 (?v "verbose" nil verbose "explain what is being done")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
224 :preserve-args
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
225 :external "rm"
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
226 :show-usage
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
227 :usage "[OPTION]... FILE...
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
228 Remove (unlink) the FILE(s).")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
229 (unless interactive
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
230 (setq interactive eshell-rm-interactive-query))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
231 (if (and force-removal interactive)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
232 (setq interactive nil))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
233 (while args
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
234 (let ((entry (if (stringp (car args))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
235 (directory-file-name (car args))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
236 (if (numberp (car args))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
237 (number-to-string (car args))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
238 (car args)))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
239 (cond
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
240 ((bufferp entry)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
241 (if verbose
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
242 (eshell-printn (format "rm: removing buffer `%s'" entry)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
243 (unless (or preview
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
244 (and interactive
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
245 (not (y-or-n-p (format "rm: delete buffer `%s'? "
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
246 entry)))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
247 (eshell-funcalln 'kill-buffer entry)))
31241
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30269
diff changeset
248 ((eshell-processp entry)
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
249 (if verbose
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
250 (eshell-printn (format "rm: killing process `%s'" entry)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
251 (unless (or preview
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
252 (and interactive
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
253 (not (y-or-n-p (format "rm: kill process `%s'? "
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
254 entry)))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
255 (eshell-funcalln 'kill-process entry)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
256 ((symbolp entry)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
257 (if verbose
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
258 (eshell-printn (format "rm: uninterning symbol `%s'" entry)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
259 (unless
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
260 (or preview
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
261 (and interactive
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
262 (not (y-or-n-p (format "rm: unintern symbol `%s'? "
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
263 entry)))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
264 (eshell-funcalln 'unintern entry)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
265 ((stringp entry)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
266 (if (and (file-directory-p entry)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
267 (not (file-symlink-p entry)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
268 (if (or recursive
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
269 eshell-rm-removes-directories)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
270 (if (or preview
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
271 (not interactive)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
272 (y-or-n-p
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
273 (format "rm: descend into directory `%s'? "
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
274 entry)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
275 (eshell-remove-entries nil (list entry) t))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
276 (eshell-error (format "rm: %s: is a directory\n" entry)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
277 (eshell-remove-entries nil (list entry) t)))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
278 (setq args (cdr args)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
279 nil))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
280
37661
6d7c89c79996 Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents: 37655
diff changeset
281 (put 'eshell/rm 'eshell-no-numeric-conversions t)
6d7c89c79996 Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents: 37655
diff changeset
282
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
283 (defun eshell/mkdir (&rest args)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
284 "Implementation of mkdir in Lisp."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
285 (eshell-eval-using-options
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
286 "mkdir" args
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
287 '((?h "help" nil nil "show this usage screen")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
288 :external "mkdir"
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
289 :show-usage
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
290 :usage "[OPTION] DIRECTORY...
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
291 Create the DIRECTORY(ies), if they do not already exist.")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
292 (while args
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
293 (eshell-funcalln 'make-directory (car args))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
294 (setq args (cdr args)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
295 nil))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
296
37661
6d7c89c79996 Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents: 37655
diff changeset
297 (put 'eshell/mkdir 'eshell-no-numeric-conversions t)
6d7c89c79996 Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents: 37655
diff changeset
298
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
299 (defun eshell/rmdir (&rest args)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
300 "Implementation of rmdir in Lisp."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
301 (eshell-eval-using-options
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
302 "rmdir" args
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
303 '((?h "help" nil nil "show this usage screen")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
304 :external "rmdir"
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
305 :show-usage
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
306 :usage "[OPTION] DIRECTORY...
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
307 Remove the DIRECTORY(ies), if they are empty.")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
308 (while args
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
309 (eshell-funcalln 'delete-directory (car args))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
310 (setq args (cdr args)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
311 nil))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
312
37661
6d7c89c79996 Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents: 37655
diff changeset
313 (put 'eshell/rmdir 'eshell-no-numeric-conversions t)
6d7c89c79996 Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents: 37655
diff changeset
314
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
315 (eval-when-compile
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
316 (defvar no-dereference)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
317 (defvar preview)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
318 (defvar verbose))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
319
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
320 (defvar eshell-warn-dot-directories t)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
321
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
322 (defun eshell-shuffle-files (command action files target func deep &rest args)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
323 "Shuffle around some filesystem entries, using FUNC to do the work."
32446
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
324 (let ((attr-target (eshell-file-attributes target))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
325 (is-dir (or (file-directory-p target)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
326 (and preview (not eshell-warn-dot-directories))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
327 attr)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
328 (if (and (not preview) (not is-dir)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
329 (> (length files) 1))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
330 (error "%s: when %s multiple files, last argument must be a directory"
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
331 command action))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
332 (while files
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
333 (setcar files (directory-file-name (car files)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
334 (cond
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
335 ((string-match "\\`\\.\\.?\\'"
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
336 (file-name-nondirectory (car files)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
337 (if eshell-warn-dot-directories
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
338 (eshell-error (format "%s: %s: omitting directory\n"
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
339 command (car files)))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
340 ((and attr-target
30269
30829e002c1b (eshell-shuffle-files): Don't disable
Eli Zaretskii <eliz@gnu.org>
parents: 29934
diff changeset
341 (or (not (eshell-under-windows-p))
30829e002c1b (eshell-shuffle-files): Don't disable
Eli Zaretskii <eliz@gnu.org>
parents: 29934
diff changeset
342 (eq system-type 'ms-dos))
32446
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
343 (setq attr (eshell-file-attributes (car files)))
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
344 (nth 10 attr-target) (nth 10 attr)
39293
1e91a5f60ae6 (eshell-shuffle-files, eshell-shuffle-files):
Eli Zaretskii <eliz@gnu.org>
parents: 39235
diff changeset
345 ;; Use equal, not -, since the inode and the device could
1e91a5f60ae6 (eshell-shuffle-files, eshell-shuffle-files):
Eli Zaretskii <eliz@gnu.org>
parents: 39235
diff changeset
346 ;; cons cells.
39235
f3a553d88ab7 (eshell-shuffle-files): Compare inodes with
Eli Zaretskii <eliz@gnu.org>
parents: 38414
diff changeset
347 (equal (nth 10 attr-target) (nth 10 attr))
32446
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
348 (nth 11 attr-target) (nth 11 attr)
39293
1e91a5f60ae6 (eshell-shuffle-files, eshell-shuffle-files):
Eli Zaretskii <eliz@gnu.org>
parents: 39235
diff changeset
349 (equal (nth 11 attr-target) (nth 11 attr)))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
350 (eshell-error (format "%s: `%s' and `%s' are the same file\n"
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
351 command (car files) target)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
352 (t
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
353 (let ((source (car files))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
354 (target (if is-dir
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
355 (expand-file-name
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
356 (file-name-nondirectory (car files)) target)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
357 target))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
358 link)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
359 (if (and (file-directory-p source)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
360 (or (not no-dereference)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
361 (not (file-symlink-p source)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
362 (not (memq func '(make-symbolic-link
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
363 add-name-to-file))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
364 (if (and (eq func 'copy-file)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
365 (not recursive))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
366 (eshell-error (format "%s: %s: omitting directory\n"
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
367 command (car files)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
368 (let (eshell-warn-dot-directories)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
369 (if (and (not deep)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
370 (eq func 'rename-file)
39293
1e91a5f60ae6 (eshell-shuffle-files, eshell-shuffle-files):
Eli Zaretskii <eliz@gnu.org>
parents: 39235
diff changeset
371 ;; Use equal, since the device might be a
1e91a5f60ae6 (eshell-shuffle-files, eshell-shuffle-files):
Eli Zaretskii <eliz@gnu.org>
parents: 39235
diff changeset
372 ;; cons cell.
1e91a5f60ae6 (eshell-shuffle-files, eshell-shuffle-files):
Eli Zaretskii <eliz@gnu.org>
parents: 39235
diff changeset
373 (equal (nth 11 (eshell-file-attributes
1e91a5f60ae6 (eshell-shuffle-files, eshell-shuffle-files):
Eli Zaretskii <eliz@gnu.org>
parents: 39235
diff changeset
374 (file-name-directory
1e91a5f60ae6 (eshell-shuffle-files, eshell-shuffle-files):
Eli Zaretskii <eliz@gnu.org>
parents: 39235
diff changeset
375 (directory-file-name
1e91a5f60ae6 (eshell-shuffle-files, eshell-shuffle-files):
Eli Zaretskii <eliz@gnu.org>
parents: 39235
diff changeset
376 (expand-file-name source)))))
1e91a5f60ae6 (eshell-shuffle-files, eshell-shuffle-files):
Eli Zaretskii <eliz@gnu.org>
parents: 39235
diff changeset
377 (nth 11 (eshell-file-attributes
1e91a5f60ae6 (eshell-shuffle-files, eshell-shuffle-files):
Eli Zaretskii <eliz@gnu.org>
parents: 39235
diff changeset
378 (file-name-directory
1e91a5f60ae6 (eshell-shuffle-files, eshell-shuffle-files):
Eli Zaretskii <eliz@gnu.org>
parents: 39235
diff changeset
379 (directory-file-name
1e91a5f60ae6 (eshell-shuffle-files, eshell-shuffle-files):
Eli Zaretskii <eliz@gnu.org>
parents: 39235
diff changeset
380 (expand-file-name target)))))))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
381 (apply 'eshell-funcalln func source target args)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
382 (unless (file-directory-p target)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
383 (if verbose
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
384 (eshell-printn
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
385 (format "%s: making directory %s"
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
386 command target)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
387 (unless preview
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
388 (eshell-funcalln 'make-directory target)))
31241
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30269
diff changeset
389 (apply 'eshell-shuffle-files
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30269
diff changeset
390 command action
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30269
diff changeset
391 (mapcar
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30269
diff changeset
392 (function
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30269
diff changeset
393 (lambda (file)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30269
diff changeset
394 (concat source "/" file)))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30269
diff changeset
395 (directory-files source))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30269
diff changeset
396 target func t args)
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
397 (when (eq func 'rename-file)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
398 (if verbose
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
399 (eshell-printn
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
400 (format "%s: deleting directory %s"
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
401 command source)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
402 (unless preview
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
403 (eshell-funcalln 'delete-directory source))))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
404 (if verbose
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
405 (eshell-printn (format "%s: %s -> %s" command
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
406 source target)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
407 (unless preview
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
408 (if (and no-dereference
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
409 (setq link (file-symlink-p source)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
410 (progn
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
411 (apply 'eshell-funcalln 'make-symbolic-link
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
412 link target args)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
413 (if (eq func 'rename-file)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
414 (if (and (file-directory-p source)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
415 (not (file-symlink-p source)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
416 (eshell-funcalln 'delete-directory source)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
417 (eshell-funcalln 'delete-file source))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
418 (apply 'eshell-funcalln func source target args)))))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
419 (setq files (cdr files)))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
420
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
421 (defun eshell-shorthand-tar-command (command args)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
422 "Rewrite `cp -v dir a.tar.gz' to `tar cvzf a.tar.gz dir'."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
423 (let* ((archive (car (last args)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
424 (tar-args
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
425 (cond ((string-match "z2" archive) "If")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
426 ((string-match "gz" archive) "zf")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
427 ((string-match "\\(az\\|Z\\)" archive) "Zf")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
428 (t "f"))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
429 (if (file-exists-p archive)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
430 (setq tar-args (concat "u" tar-args))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
431 (setq tar-args (concat "c" tar-args)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
432 (if verbose
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
433 (setq tar-args (concat "v" tar-args)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
434 (if (equal command "mv")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
435 (setq tar-args (concat "--remove-files -" tar-args)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
436 ;; truncate the archive name from the arguments
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
437 (setcdr (last args 2) nil)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
438 (throw 'eshell-replace-command
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
439 (eshell-parse-command
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
440 (format "tar %s %s" tar-args archive) args))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
441
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
442 ;; this is to avoid duplicating code...
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
443 (defmacro eshell-mvcpln-template (command action func query-var
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
444 force-var &optional preserve)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
445 `(let ((len (length args)))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
446 (if (or (= len 0)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
447 (and (= len 1) (null eshell-default-target-is-dot)))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
448 (error "%s: missing destination file or directory" ,command))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
449 (if (= len 1)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
450 (nconc args '(".")))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
451 (setq args (eshell-stringify-list (eshell-flatten-list args)))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
452 (if (and ,(not (equal command "ln"))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
453 (string-match eshell-tar-regexp (car (last args)))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
454 (or (> (length args) 2)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
455 (and (file-directory-p (car args))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
456 (or (not no-dereference)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
457 (not (file-symlink-p (car args)))))))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
458 (eshell-shorthand-tar-command ,command args)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
459 (let ((target (car (last args)))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
460 ange-cache)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
461 (setcdr (last args 2) nil)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
462 (eshell-shuffle-files
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
463 ,command ,action args target ,func nil
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
464 ,@(append
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
465 `((if (and (or interactive
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
466 ,query-var)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
467 (not force))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
468 1 (or force ,force-var)))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
469 (if preserve
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
470 (list preserve)))))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
471 nil)))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
472
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
473 (defun eshell/mv (&rest args)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
474 "Implementation of mv in Lisp."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
475 (eshell-eval-using-options
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
476 "mv" args
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
477 '((?f "force" nil force
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
478 "remove existing destinations, never prompt")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
479 (?i "interactive" nil interactive
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
480 "request confirmation if target already exists")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
481 (?n "preview" nil preview
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
482 "don't change anything on disk")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
483 (?v "verbose" nil verbose
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
484 "explain what is being done")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
485 (nil "help" nil nil "show this usage screen")
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
486 :preserve-args
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
487 :external "mv"
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
488 :show-usage
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
489 :usage "[OPTION]... SOURCE DEST
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
490 or: mv [OPTION]... SOURCE... DIRECTORY
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
491 Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
492 \[OPTION] DIRECTORY...")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
493 (let ((no-dereference t))
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
494 (eshell-mvcpln-template "mv" "moving" 'rename-file
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
495 eshell-mv-interactive-query
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
496 eshell-mv-overwrite-files))))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
497
37661
6d7c89c79996 Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents: 37655
diff changeset
498 (put 'eshell/mv 'eshell-no-numeric-conversions t)
6d7c89c79996 Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents: 37655
diff changeset
499
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
500 (defun eshell/cp (&rest args)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
501 "Implementation of cp in Lisp."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
502 (eshell-eval-using-options
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
503 "cp" args
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
504 '((?a "archive" nil archive
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
505 "same as -dpR")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
506 (?d "no-dereference" nil no-dereference
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
507 "preserve links")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
508 (?f "force" nil force
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
509 "remove existing destinations, never prompt")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
510 (?i "interactive" nil interactive
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
511 "request confirmation if target already exists")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
512 (?n "preview" nil preview
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
513 "don't change anything on disk")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
514 (?p "preserve" nil preserve
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
515 "preserve file attributes if possible")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
516 (?R "recursive" nil recursive
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
517 "copy directories recursively")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
518 (?v "verbose" nil verbose
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
519 "explain what is being done")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
520 (nil "help" nil nil "show this usage screen")
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
521 :preserve-args
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
522 :external "cp"
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
523 :show-usage
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
524 :usage "[OPTION]... SOURCE DEST
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
525 or: cp [OPTION]... SOURCE... DIRECTORY
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
526 Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
527 (if archive
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
528 (setq preserve t no-dereference t recursive t))
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
529 (eshell-mvcpln-template "cp" "copying" 'copy-file
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
530 eshell-cp-interactive-query
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
531 eshell-cp-overwrite-files preserve)))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
532
37661
6d7c89c79996 Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents: 37655
diff changeset
533 (put 'eshell/cp 'eshell-no-numeric-conversions t)
6d7c89c79996 Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents: 37655
diff changeset
534
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
535 (defun eshell/ln (&rest args)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
536 "Implementation of ln in Lisp."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
537 (eshell-eval-using-options
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
538 "ln" args
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
539 '((?h "help" nil nil "show this usage screen")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
540 (?s "symbolic" nil symbolic
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
541 "make symbolic links instead of hard links")
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
542 (?i "interactive" nil interactive
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
543 "request confirmation if target already exists")
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
544 (?f "force" nil force "remove existing destinations, never prompt")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
545 (?n "preview" nil preview
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
546 "don't change anything on disk")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
547 (?v "verbose" nil verbose "explain what is being done")
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
548 :preserve-args
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
549 :external "ln"
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
550 :show-usage
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
551 :usage "[OPTION]... TARGET [LINK_NAME]
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
552 or: ln [OPTION]... TARGET... DIRECTORY
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
553 Create a link to the specified TARGET with optional LINK_NAME. If there is
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
554 more than one TARGET, the last argument must be a directory; create links
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
555 in DIRECTORY to each TARGET. Create hard links by default, symbolic links
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
556 with '--symbolic'. When creating hard links, each TARGET must exist.")
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
557 (let ((no-dereference t))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
558 (eshell-mvcpln-template "ln" "linking"
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
559 (if symbolic
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
560 'make-symbolic-link
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
561 'add-name-to-file)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
562 eshell-ln-interactive-query
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
563 eshell-ln-overwrite-files))))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
564
37661
6d7c89c79996 Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents: 37655
diff changeset
565 (put 'eshell/ln 'eshell-no-numeric-conversions t)
6d7c89c79996 Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents: 37655
diff changeset
566
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
567 (defun eshell/cat (&rest args)
32446
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
568 "Implementation of cat in Lisp.
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
569 If in a pipeline, or the file is not a regular file, directory or
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
570 symlink, then revert to the system's definition of cat."
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
571 (setq args (eshell-stringify-list (eshell-flatten-list args)))
32446
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
572 (if (or eshell-in-pipeline-p
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
573 (catch 'special
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
574 (eshell-for arg args
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
575 (unless (let ((attrs (eshell-file-attributes arg)))
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
576 (and attrs (memq (aref (nth 8 attrs) 0)
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
577 '(?d ?l ?-))))
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
578 (throw 'special t)))))
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
579 (let ((ext-cat (eshell-search-path "cat")))
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
580 (if ext-cat
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
581 (throw 'eshell-replace-command
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
582 (eshell-parse-command ext-cat args))
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
583 (if eshell-in-pipeline-p
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
584 (error "Eshell's `cat' does not work in pipelines")
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
585 (error "Eshell's `cat' cannot display one of the files given"))))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
586 (eshell-init-print-buffer)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
587 (eshell-eval-using-options
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
588 "cat" args
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
589 '((?h "help" nil nil "show this usage screen")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
590 :external "cat"
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
591 :show-usage
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
592 :usage "[OPTION] FILE...
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
593 Concatenate FILE(s), or standard input, to standard output.")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
594 (eshell-for file args
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
595 (if (string= file "-")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
596 (throw 'eshell-external
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
597 (eshell-external-command "cat" args))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
598 (let ((curbuf (current-buffer)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
599 (eshell-for file args
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
600 (with-temp-buffer
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
601 (insert-file-contents file)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
602 (goto-char (point-min))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
603 (while (not (eobp))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
604 (let ((str (buffer-substring
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
605 (point) (min (1+ (line-end-position))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
606 (point-max)))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
607 (with-current-buffer curbuf
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
608 (eshell-buffered-print str)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
609 (forward-line)))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
610 (eshell-flush)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
611 ;; if the file does not end in a newline, do not emit one
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
612 (setq eshell-ensure-newline-p nil))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
613
37661
6d7c89c79996 Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents: 37655
diff changeset
614 (put 'eshell/cat 'eshell-no-numeric-conversions t)
6d7c89c79996 Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents: 37655
diff changeset
615
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
616 ;; special front-end functions for compilation-mode buffers
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
617
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
618 (defun eshell/make (&rest args)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
619 "Use `compile' to do background makes."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
620 (if (and eshell-current-subjob-p
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
621 (eshell-interactive-output-p))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
622 (let ((compilation-process-setup-function
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
623 (list 'lambda nil
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
624 (list 'setq 'process-environment
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
625 (list 'quote (eshell-copy-environment))))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
626 (compile (concat "make " (eshell-flatten-and-stringify args))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
627 (throw 'eshell-replace-command
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
628 (eshell-parse-command "*make" (eshell-stringify-list
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
629 (eshell-flatten-list args))))))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
630
37661
6d7c89c79996 Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents: 37655
diff changeset
631 (put 'eshell/make 'eshell-no-numeric-conversions t)
6d7c89c79996 Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents: 37655
diff changeset
632
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
633 (defun eshell-occur-mode-goto-occurrence ()
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
634 "Go to the occurrence the current line describes."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
635 (interactive)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
636 (let ((pos (occur-mode-find-occurrence)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
637 (pop-to-buffer (marker-buffer pos))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
638 (goto-char (marker-position pos))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
639
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
640 (defun eshell-occur-mode-mouse-goto (event)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
641 "In Occur mode, go to the occurrence whose line you click on."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
642 (interactive "e")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
643 (let (buffer pos)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
644 (save-excursion
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
645 (set-buffer (window-buffer (posn-window (event-end event))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
646 (save-excursion
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
647 (goto-char (posn-point (event-end event)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
648 (setq pos (occur-mode-find-occurrence))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
649 (setq buffer occur-buffer)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
650 (pop-to-buffer (marker-buffer pos))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
651 (goto-char (marker-position pos))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
652
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
653 (defun eshell-poor-mans-grep (args)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
654 "A poor version of grep that opens every file and uses `occur'.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
655 This eats up memory, since it leaves the buffers open (to speed future
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
656 searches), and it's very slow. But, if your system has no grep
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
657 available..."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
658 (save-selected-window
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
659 (let ((default-dir default-directory))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
660 (with-current-buffer (get-buffer-create "*grep*")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
661 (let ((inhibit-read-only t)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
662 (default-directory default-dir))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
663 (erase-buffer)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
664 (occur-mode)
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
665 (let ((files (eshell-stringify-list
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
666 (eshell-flatten-list (cdr args))))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
667 (inhibit-redisplay t)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
668 string)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
669 (when (car args)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
670 (if (get-buffer "*Occur*")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
671 (kill-buffer (get-buffer "*Occur*")))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
672 (setq string nil)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
673 (while files
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
674 (with-current-buffer (find-file-noselect (car files))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
675 (save-excursion
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
676 (ignore-errors
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
677 (occur (car args))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
678 (if (get-buffer "*Occur*")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
679 (with-current-buffer (get-buffer "*Occur*")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
680 (setq string (buffer-string))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
681 (kill-buffer (current-buffer)))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
682 (if string (insert string))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
683 (setq string nil
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
684 files (cdr files)))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
685 (setq occur-buffer (current-buffer))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
686 (local-set-key [mouse-2] 'eshell-occur-mode-mouse-goto)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
687 (local-set-key [(control ?c) (control ?c)]
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
688 'eshell-occur-mode-goto-occurrence)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
689 (local-set-key [(control ?m)]
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
690 'eshell-occur-mode-goto-occurrence)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
691 (local-set-key [return] 'eshell-occur-mode-goto-occurrence)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
692 (pop-to-buffer (current-buffer) t)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
693 (goto-char (point-min))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
694 (resize-temp-buffer-window))))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
695
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
696 (defun eshell-grep (command args &optional maybe-use-occur)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
697 "Generic service function for the various grep aliases.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
698 It calls Emacs' grep utility if the command is not redirecting output,
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
699 and if it's not part of a command pipeline. Otherwise, it calls the
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
700 external command."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
701 (if (and maybe-use-occur eshell-no-grep-available)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
702 (eshell-poor-mans-grep args)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
703 (if (or eshell-plain-grep-behavior
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
704 (not (and (eshell-interactive-output-p)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
705 (not eshell-in-pipeline-p)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
706 (not eshell-in-subcommand-p))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
707 (throw 'eshell-replace-command
31241
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30269
diff changeset
708 (eshell-parse-command (concat "*" command)
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
709 (eshell-stringify-list
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
710 (eshell-flatten-list args))))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
711 (let* ((compilation-process-setup-function
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
712 (list 'lambda nil
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
713 (list 'setq 'process-environment
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
714 (list 'quote (eshell-copy-environment)))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
715 (args (mapconcat 'identity
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
716 (mapcar 'shell-quote-argument
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
717 (eshell-stringify-list
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
718 (eshell-flatten-list args)))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
719 " "))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
720 (cmd (progn
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
721 (set-text-properties 0 (length args)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
722 '(invisible t) args)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
723 (format "%s -n %s" command args)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
724 compilation-scroll-output)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
725 (grep cmd)))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
726
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
727 (defun eshell/grep (&rest args)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
728 "Use Emacs grep facility instead of calling external grep."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
729 (eshell-grep "grep" args t))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
730
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
731 (defun eshell/egrep (&rest args)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
732 "Use Emacs grep facility instead of calling external egrep."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
733 (eshell-grep "egrep" args t))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
734
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
735 (defun eshell/fgrep (&rest args)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
736 "Use Emacs grep facility instead of calling external fgrep."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
737 (eshell-grep "fgrep" args t))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
738
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
739 (defun eshell/agrep (&rest args)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
740 "Use Emacs grep facility instead of calling external agrep."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
741 (eshell-grep "agrep" args))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
742
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
743 (defun eshell/glimpse (&rest args)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
744 "Use Emacs grep facility instead of calling external glimpse."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
745 (let (null-device)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
746 (eshell-grep "glimpse" (append '("-z" "-y") args))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
747
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
748 ;; completions rules for some common UNIX commands
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
749
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
750 (defsubst eshell-complete-hostname ()
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
751 "Complete a command that wants a hostname for an argument."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
752 (pcomplete-here (eshell-read-host-names)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
753
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
754 (defun eshell-complete-host-reference ()
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
755 "If there is a host reference, complete it."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
756 (let ((arg (pcomplete-actual-arg))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
757 index)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
758 (when (setq index (string-match "@[a-z.]*\\'" arg))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
759 (setq pcomplete-stub (substring arg (1+ index))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
760 pcomplete-last-completion-raw t)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
761 (throw 'pcomplete-completions (eshell-read-host-names)))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
762
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
763 (defalias 'pcomplete/ftp 'eshell-complete-hostname)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
764 (defalias 'pcomplete/ncftp 'eshell-complete-hostname)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
765 (defalias 'pcomplete/ping 'eshell-complete-hostname)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
766 (defalias 'pcomplete/rlogin 'eshell-complete-hostname)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
767
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
768 (defun pcomplete/telnet ()
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
769 (require 'pcmpl-unix)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
770 (pcomplete-opt "xl(pcmpl-unix-user-names)")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
771 (eshell-complete-hostname))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
772
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
773 (defun pcomplete/rsh ()
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
774 "Complete `rsh', which, after the user and hostname, is like xargs."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
775 (require 'pcmpl-unix)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
776 (pcomplete-opt "l(pcmpl-unix-user-names)")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
777 (eshell-complete-hostname)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
778 (pcomplete-here (funcall pcomplete-command-completion-function))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
779 (funcall (or (pcomplete-find-completion-function (pcomplete-arg 1))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
780 pcomplete-default-completion-function)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
781
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
782 (defalias 'pcomplete/ssh 'pcomplete/rsh)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
783
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
784 (eval-when-compile
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
785 (defvar block-size)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
786 (defvar by-bytes)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
787 (defvar dereference-links)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
788 (defvar grand-total)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
789 (defvar human-readable)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
790 (defvar max-depth)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
791 (defvar only-one-filesystem)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
792 (defvar show-all))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
793
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
794 (defsubst eshell-du-size-string (size)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
795 (let* ((str (eshell-printable-size size human-readable block-size t))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
796 (len (length str)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
797 (concat str (if (< len 8)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
798 (make-string (- 8 len) ? )))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
799
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
800 (defun eshell-du-sum-directory (path depth)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
801 "Summarize PATH, and its member directories."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
802 (let ((entries (eshell-directory-files-and-attributes path))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
803 (size 0.0))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
804 (while entries
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
805 (unless (string-match "\\`\\.\\.?\\'" (caar entries))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
806 (let* ((entry (concat path (char-to-string directory-sep-char)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
807 (caar entries)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
808 (symlink (and (stringp (cadr (car entries)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
809 (cadr (car entries)))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
810 (unless (or (and symlink (not dereference-links))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
811 (and only-one-filesystem
31241
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30269
diff changeset
812 (/= only-one-filesystem
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30269
diff changeset
813 (nth 12 (car entries)))))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
814 (if symlink
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
815 (setq entry symlink))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
816 (setq size
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
817 (+ size
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
818 (if (eq t (cadr (car entries)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
819 (eshell-du-sum-directory entry (1+ depth))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
820 (let ((file-size (nth 8 (car entries))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
821 (prog1
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
822 file-size
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
823 (if show-all
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
824 (eshell-print
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
825 (concat (eshell-du-size-string file-size)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
826 entry "\n")))))))))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
827 (setq entries (cdr entries)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
828 (if (or (not max-depth)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
829 (= depth max-depth)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
830 (= depth 0))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
831 (eshell-print (concat (eshell-du-size-string size)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
832 (directory-file-name path) "\n")))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
833 size))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
834
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
835 (defun eshell/du (&rest args)
31241
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30269
diff changeset
836 "Implementation of \"du\" in Lisp, passing ARGS."
32446
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
837 (setq args (if args
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
838 (eshell-stringify-list (eshell-flatten-list args))
32446
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
839 '(".")))
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
840 (let ((ext-du (eshell-search-path "du")))
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
841 (if (and ext-du
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
842 (not (catch 'have-ange-path
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
843 (eshell-for arg args
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
844 (if (eq (find-file-name-handler (expand-file-name arg)
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
845 'directory-files)
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
846 'ange-ftp-hook-function)
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
847 (throw 'have-ange-path t))))))
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
848 (throw 'eshell-replace-command
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
849 (eshell-parse-command ext-du args))
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
850 (eshell-eval-using-options
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
851 "du" args
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
852 '((?a "all" nil show-all
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
853 "write counts for all files, not just directories")
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
854 (nil "block-size" t block-size
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
855 "use SIZE-byte blocks (i.e., --block-size SIZE)")
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
856 (?b "bytes" nil by-bytes
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
857 "print size in bytes")
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
858 (?c "total" nil grand-total
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
859 "produce a grand total")
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
860 (?d "max-depth" t max-depth
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
861 "display data only this many levels of data")
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
862 (?h "human-readable" 1024 human-readable
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
863 "print sizes in human readable format")
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
864 (?H "is" 1000 human-readable
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
865 "likewise, but use powers of 1000 not 1024")
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
866 (?k "kilobytes" 1024 block-size
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
867 "like --block-size 1024")
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
868 (?L "dereference" nil dereference-links
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
869 "dereference all symbolic links")
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
870 (?m "megabytes" 1048576 block-size
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
871 "like --block-size 1048576")
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
872 (?s "summarize" 0 max-depth
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
873 "display only a total for each argument")
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
874 (?x "one-file-system" nil only-one-filesystem
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
875 "skip directories on different filesystems")
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
876 (nil "help" nil nil
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
877 "show this usage screen")
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
878 :external "du"
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
879 :usage "[OPTION]... FILE...
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
880 Summarize disk usage of each FILE, recursively for directories.")
32446
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
881 (unless by-bytes
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
882 (setq block-size (or block-size 1024)))
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
883 (if (and max-depth (stringp max-depth))
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
884 (setq max-depth (string-to-int max-depth)))
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
885 ;; filesystem support means nothing under Windows
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
886 (if (eshell-under-windows-p)
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
887 (setq only-one-filesystem nil))
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
888 (let ((size 0.0) ange-cache)
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
889 (while args
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
890 (if only-one-filesystem
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
891 (setq only-one-filesystem
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
892 (nth 11 (eshell-file-attributes
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
893 (file-name-as-directory (car args))))))
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
894 (setq size (+ size (eshell-du-sum-directory
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
895 (directory-file-name (car args)) 0)))
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
896 (setq args (cdr args)))
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
897 (if grand-total
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
898 (eshell-print (concat (eshell-du-size-string size)
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
899 "total\n"))))))))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
900
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
901 (defvar eshell-time-start nil)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
902
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
903 (defun eshell-show-elapsed-time ()
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
904 (let ((elapsed (format "%.3f secs\n"
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
905 (- (eshell-time-to-seconds (current-time))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
906 eshell-time-start))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
907 (set-text-properties 0 (length elapsed) '(face bold) elapsed)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
908 (eshell-interactive-print elapsed))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
909 (remove-hook 'eshell-post-command-hook 'eshell-show-elapsed-time t))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
910
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
911 (defun eshell/time (&rest args)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
912 "Implementation of \"time\" in Lisp."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
913 (let ((time-args (copy-alist args))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
914 (continue t)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
915 last-arg)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
916 (while (and continue args)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
917 (if (not (string-match "^-" (car args)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
918 (progn
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
919 (if last-arg
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
920 (setcdr last-arg nil)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
921 (setq args '("")))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
922 (setq continue nil))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
923 (setq last-arg args
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
924 args (cdr args))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
925 (eshell-eval-using-options
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
926 "time" args
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
927 '((?h "help" nil nil "show this usage screen")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
928 :external "time"
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
929 :show-usage
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
930 :usage "COMMAND...
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
931 Show wall-clock time elapsed during execution of COMMAND.")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
932 (setq eshell-time-start (eshell-time-to-seconds (current-time)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
933 (add-hook 'eshell-post-command-hook 'eshell-show-elapsed-time nil t)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
934 ;; after setting
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
935 (throw 'eshell-replace-command
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
936 (eshell-parse-command (car time-args) (cdr time-args))))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
937
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
938 (defalias 'eshell/whoami 'user-login-name)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
939
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
940 (defvar eshell-diff-window-config nil)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
941
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
942 (defun eshell-diff-quit ()
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
943 "Restore the window configuration previous to diff'ing."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
944 (interactive)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
945 (if eshell-diff-window-config
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
946 (set-window-configuration eshell-diff-window-config)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
947
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
948 (defun eshell/diff (&rest args)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
949 "Alias \"diff\" to call Emacs `diff' function."
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
950 (let ((orig-args (eshell-stringify-list (eshell-flatten-list args))))
31241
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30269
diff changeset
951 (if (or eshell-plain-diff-behavior
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30269
diff changeset
952 (not (and (eshell-interactive-output-p)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30269
diff changeset
953 (not eshell-in-pipeline-p)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30269
diff changeset
954 (not eshell-in-subcommand-p))))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30269
diff changeset
955 (throw 'eshell-replace-command
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30269
diff changeset
956 (eshell-parse-command "*diff" orig-args))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30269
diff changeset
957 (setq args (eshell-copy-list orig-args))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30269
diff changeset
958 (if (< (length args) 2)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30269
diff changeset
959 (throw 'eshell-replace-command
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30269
diff changeset
960 (eshell-parse-command "*diff" orig-args)))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30269
diff changeset
961 (let ((old (car (last args 2)))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30269
diff changeset
962 (new (car (last args)))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30269
diff changeset
963 (config (current-window-configuration)))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30269
diff changeset
964 (if (= (length args) 2)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30269
diff changeset
965 (setq args nil)
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30269
diff changeset
966 (setcdr (last args 3) nil))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30269
diff changeset
967 (with-current-buffer
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30269
diff changeset
968 (condition-case err
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30269
diff changeset
969 (diff old new (eshell-flatten-and-stringify args))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30269
diff changeset
970 (error
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30269
diff changeset
971 (throw 'eshell-replace-command
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30269
diff changeset
972 (eshell-parse-command "*diff" orig-args))))
3099993cba0f See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 30269
diff changeset
973 (when (fboundp 'diff-mode)
37441
565e55bc8630 (eshell/diff): Fixed problems that were occurring with Emacs 21's
John Wiegley <johnw@newartisans.com>
parents: 35588
diff changeset
974 (make-local-variable 'compilation-finish-functions)
565e55bc8630 (eshell/diff): Fixed problems that were occurring with Emacs 21's
John Wiegley <johnw@newartisans.com>
parents: 35588
diff changeset
975 (add-hook
565e55bc8630 (eshell/diff): Fixed problems that were occurring with Emacs 21's
John Wiegley <johnw@newartisans.com>
parents: 35588
diff changeset
976 'compilation-finish-functions
565e55bc8630 (eshell/diff): Fixed problems that were occurring with Emacs 21's
John Wiegley <johnw@newartisans.com>
parents: 35588
diff changeset
977 `(lambda (buff msg)
565e55bc8630 (eshell/diff): Fixed problems that were occurring with Emacs 21's
John Wiegley <johnw@newartisans.com>
parents: 35588
diff changeset
978 (with-current-buffer buff
565e55bc8630 (eshell/diff): Fixed problems that were occurring with Emacs 21's
John Wiegley <johnw@newartisans.com>
parents: 35588
diff changeset
979 (diff-mode)
565e55bc8630 (eshell/diff): Fixed problems that were occurring with Emacs 21's
John Wiegley <johnw@newartisans.com>
parents: 35588
diff changeset
980 (set (make-local-variable 'eshell-diff-window-config)
565e55bc8630 (eshell/diff): Fixed problems that were occurring with Emacs 21's
John Wiegley <johnw@newartisans.com>
parents: 35588
diff changeset
981 ,config)
565e55bc8630 (eshell/diff): Fixed problems that were occurring with Emacs 21's
John Wiegley <johnw@newartisans.com>
parents: 35588
diff changeset
982 (local-set-key [?q] 'eshell-diff-quit)
565e55bc8630 (eshell/diff): Fixed problems that were occurring with Emacs 21's
John Wiegley <johnw@newartisans.com>
parents: 35588
diff changeset
983 (if (fboundp 'turn-on-font-lock-if-enabled)
565e55bc8630 (eshell/diff): Fixed problems that were occurring with Emacs 21's
John Wiegley <johnw@newartisans.com>
parents: 35588
diff changeset
984 (turn-on-font-lock-if-enabled))
565e55bc8630 (eshell/diff): Fixed problems that were occurring with Emacs 21's
John Wiegley <johnw@newartisans.com>
parents: 35588
diff changeset
985 (goto-char (point-min))))))
565e55bc8630 (eshell/diff): Fixed problems that were occurring with Emacs 21's
John Wiegley <johnw@newartisans.com>
parents: 35588
diff changeset
986 (pop-to-buffer (current-buffer))))))
565e55bc8630 (eshell/diff): Fixed problems that were occurring with Emacs 21's
John Wiegley <johnw@newartisans.com>
parents: 35588
diff changeset
987 nil)
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
988
37661
6d7c89c79996 Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents: 37655
diff changeset
989 (put 'eshell/diff 'eshell-no-numeric-conversions t)
6d7c89c79996 Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents: 37655
diff changeset
990
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
991 (defun eshell/locate (&rest args)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
992 "Alias \"locate\" to call Emacs `locate' function."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
993 (if (or eshell-plain-locate-behavior
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
994 (not (and (eshell-interactive-output-p)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
995 (not eshell-in-pipeline-p)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
996 (not eshell-in-subcommand-p)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
997 (and (stringp (car args))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
998 (string-match "^-" (car args))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
999 (throw 'eshell-replace-command
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
1000 (eshell-parse-command "*locate" (eshell-stringify-list
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
1001 (eshell-flatten-list args))))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1002 (save-selected-window
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1003 (let ((locate-history-list (list (car args))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1004 (locate-with-filter (car args) (cadr args))))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1005
37661
6d7c89c79996 Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents: 37655
diff changeset
1006 (put 'eshell/locate 'eshell-no-numeric-conversions t)
6d7c89c79996 Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents: 37655
diff changeset
1007
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1008 (defun eshell/occur (&rest args)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1009 "Alias \"occur\" to call Emacs `occur' function."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1010 (let ((inhibit-read-only t))
35588
31904bdf4350 See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 33020
diff changeset
1011 (if (> (length args) 2)
31904bdf4350 See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 33020
diff changeset
1012 (error "usage: occur: (REGEXP &optional NLINES)")
31904bdf4350 See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 33020
diff changeset
1013 (apply 'occur args))))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1014
37661
6d7c89c79996 Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents: 37655
diff changeset
1015 (put 'eshell/occur 'eshell-no-numeric-conversions t)
6d7c89c79996 Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents: 37655
diff changeset
1016
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1017 ;;; Code:
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1018
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1019 ;;; em-unix.el ends here