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