Mercurial > emacs
annotate lisp/eshell/em-unix.el @ 32575:7f8af667c707
(fancy-splash-text): Realign the text.
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Tue, 17 Oct 2000 12:10:40 +0000 |
parents | 8e57189d61b4 |
children | e21feeab77fb |
rev | line source |
---|---|
29876 | 1 ;;; em-unix --- UNIX command aliases |
2 | |
29934
34b1ab9d583d
Change spelling of the Free Software Foundation.
Gerd Moellmann <gerd@gnu.org>
parents:
29876
diff
changeset
|
3 ;; Copyright (C) 1999, 2000 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 | |
32446
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
127 (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
|
128 "*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
|
129 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
|
130 :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
|
131 :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
|
132 |
29876 | 133 (require 'esh-opt) |
134 | |
135 ;;; Functions: | |
136 | |
137 (defun eshell-unix-initialize () | |
138 "Initialize the UNIX support/emulation code." | |
139 (make-local-hook 'eshell-post-command-hook) | |
140 (when (eshell-using-module 'eshell-cmpl) | |
141 (make-local-hook 'pcomplete-try-first-hook) | |
142 (add-hook 'pcomplete-try-first-hook | |
143 'eshell-complete-host-reference nil t))) | |
144 | |
145 (defalias 'eshell/date 'current-time-string) | |
146 (defalias 'eshell/basename 'file-name-nondirectory) | |
147 (defalias 'eshell/dirname 'file-name-directory) | |
148 | |
149 (eval-when-compile | |
150 (defvar interactive) | |
151 (defvar preview) | |
152 (defvar recursive) | |
153 (defvar verbose)) | |
154 | |
155 (defun eshell/man (&rest args) | |
156 "Invoke man, flattening the arguments appropriately." | |
157 (funcall 'man (apply 'eshell-flatten-and-stringify args))) | |
158 | |
159 (defun eshell-remove-entries (path files &optional top-level) | |
160 (while files | |
161 (if (string-match "\\`\\.\\.?\\'" | |
162 (file-name-nondirectory (car files))) | |
163 (if top-level | |
164 (eshell-error "rm: cannot remove `.' or `..'\n")) | |
165 (if (and (file-directory-p (car files)) | |
166 (not (file-symlink-p (car files)))) | |
167 (let ((dir (file-name-as-directory (car files)))) | |
168 (eshell-remove-entries dir | |
169 (mapcar | |
170 (function | |
171 (lambda (file) | |
172 (concat dir file))) | |
173 (directory-files dir))) | |
174 (if verbose | |
175 (eshell-printn (format "rm: removing directory `%s'" | |
176 (car files)))) | |
177 (unless | |
178 (or preview | |
179 (and interactive | |
180 (not (y-or-n-p | |
181 (format "rm: remove directory `%s'? " | |
182 (car files)))))) | |
183 (eshell-funcalln 'delete-directory (car files)))) | |
184 (if verbose | |
185 (eshell-printn (format "rm: removing file `%s'" | |
186 (car files)))) | |
187 (unless (or preview | |
188 (and interactive | |
189 (not (y-or-n-p | |
190 (format "rm: remove `%s'? " | |
191 (car files)))))) | |
192 (eshell-funcalln 'delete-file (car files))))) | |
193 (setq files (cdr files)))) | |
194 | |
195 (defun eshell/rm (&rest args) | |
196 "Implementation of rm in Lisp. | |
197 This is implemented to call either `delete-file', `kill-buffer', | |
198 `kill-process', or `unintern', depending on the nature of the | |
199 argument." | |
200 (setq args (eshell-flatten-list args)) | |
201 (eshell-eval-using-options | |
202 "rm" args | |
203 '((?h "help" nil nil "show this usage screen") | |
204 (?f "force" nil force-removal "force removal") | |
205 (?i "interactive" nil interactive "prompt before any removal") | |
206 (?n "preview" nil preview "don't change anything on disk") | |
207 (?r "recursive" nil recursive | |
208 "remove the contents of directories recursively") | |
209 (?R nil nil recursive "(same)") | |
210 (?v "verbose" nil verbose "explain what is being done") | |
211 :preserve-args | |
212 :external "rm" | |
213 :show-usage | |
214 :usage "[OPTION]... FILE... | |
215 Remove (unlink) the FILE(s).") | |
216 (unless interactive | |
217 (setq interactive eshell-rm-interactive-query)) | |
218 (if (and force-removal interactive) | |
219 (setq interactive nil)) | |
220 (while args | |
221 (let ((entry (if (stringp (car args)) | |
222 (directory-file-name (car args)) | |
223 (if (numberp (car args)) | |
224 (number-to-string (car args)) | |
225 (car args))))) | |
226 (cond | |
227 ((bufferp entry) | |
228 (if verbose | |
229 (eshell-printn (format "rm: removing buffer `%s'" entry))) | |
230 (unless (or preview | |
231 (and interactive | |
232 (not (y-or-n-p (format "rm: delete buffer `%s'? " | |
233 entry))))) | |
234 (eshell-funcalln 'kill-buffer entry))) | |
31241 | 235 ((eshell-processp entry) |
29876 | 236 (if verbose |
237 (eshell-printn (format "rm: killing process `%s'" entry))) | |
238 (unless (or preview | |
239 (and interactive | |
240 (not (y-or-n-p (format "rm: kill process `%s'? " | |
241 entry))))) | |
242 (eshell-funcalln 'kill-process entry))) | |
243 ((symbolp entry) | |
244 (if verbose | |
245 (eshell-printn (format "rm: uninterning symbol `%s'" entry))) | |
246 (unless | |
247 (or preview | |
248 (and interactive | |
249 (not (y-or-n-p (format "rm: unintern symbol `%s'? " | |
250 entry))))) | |
251 (eshell-funcalln 'unintern entry))) | |
252 ((stringp entry) | |
253 (if (and (file-directory-p entry) | |
254 (not (file-symlink-p entry))) | |
255 (if (or recursive | |
256 eshell-rm-removes-directories) | |
257 (if (or preview | |
258 (not interactive) | |
259 (y-or-n-p | |
260 (format "rm: descend into directory `%s'? " | |
261 entry))) | |
262 (eshell-remove-entries nil (list entry) t)) | |
263 (eshell-error (format "rm: %s: is a directory\n" entry))) | |
264 (eshell-remove-entries nil (list entry) t))))) | |
265 (setq args (cdr args))) | |
266 nil)) | |
267 | |
268 (defun eshell/mkdir (&rest args) | |
269 "Implementation of mkdir in Lisp." | |
270 (eshell-eval-using-options | |
271 "mkdir" args | |
272 '((?h "help" nil nil "show this usage screen") | |
273 :external "mkdir" | |
274 :show-usage | |
275 :usage "[OPTION] DIRECTORY... | |
276 Create the DIRECTORY(ies), if they do not already exist.") | |
277 (while args | |
278 (eshell-funcalln 'make-directory (car args)) | |
279 (setq args (cdr args))) | |
280 nil)) | |
281 | |
282 (defun eshell/rmdir (&rest args) | |
283 "Implementation of rmdir in Lisp." | |
284 (eshell-eval-using-options | |
285 "rmdir" args | |
286 '((?h "help" nil nil "show this usage screen") | |
287 :external "rmdir" | |
288 :show-usage | |
289 :usage "[OPTION] DIRECTORY... | |
290 Remove the DIRECTORY(ies), if they are empty.") | |
291 (while args | |
292 (eshell-funcalln 'delete-directory (car args)) | |
293 (setq args (cdr args))) | |
294 nil)) | |
295 | |
296 (eval-when-compile | |
297 (defvar no-dereference) | |
298 (defvar preview) | |
299 (defvar verbose)) | |
300 | |
301 (defvar eshell-warn-dot-directories t) | |
302 | |
303 (defun eshell-shuffle-files (command action files target func deep &rest args) | |
304 "Shuffle around some filesystem entries, using FUNC to do the work." | |
305 (if (null target) | |
306 (error "%s: missing destination file" command)) | |
32446
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
307 (let ((attr-target (eshell-file-attributes target)) |
29876 | 308 (is-dir (or (file-directory-p target) |
309 (and preview (not eshell-warn-dot-directories)))) | |
310 attr) | |
311 (if (and (not preview) (not is-dir) | |
312 (> (length files) 1)) | |
313 (error "%s: when %s multiple files, last argument must be a directory" | |
314 command action)) | |
315 (while files | |
316 (setcar files (directory-file-name (car files))) | |
317 (cond | |
318 ((string-match "\\`\\.\\.?\\'" | |
319 (file-name-nondirectory (car files))) | |
320 (if eshell-warn-dot-directories | |
321 (eshell-error (format "%s: %s: omitting directory\n" | |
322 command (car files))))) | |
323 ((and attr-target | |
30269
30829e002c1b
(eshell-shuffle-files): Don't disable
Eli Zaretskii <eliz@gnu.org>
parents:
29934
diff
changeset
|
324 (or (not (eshell-under-windows-p)) |
30829e002c1b
(eshell-shuffle-files): Don't disable
Eli Zaretskii <eliz@gnu.org>
parents:
29934
diff
changeset
|
325 (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
|
326 (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
|
327 (nth 10 attr-target) (nth 10 attr) |
29876 | 328 (= (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
|
329 (nth 11 attr-target) (nth 11 attr) |
29876 | 330 (= (nth 11 attr-target) (nth 11 attr))) |
331 (eshell-error (format "%s: `%s' and `%s' are the same file\n" | |
332 command (car files) target))) | |
333 (t | |
334 (let ((source (car files)) | |
335 (target (if is-dir | |
336 (expand-file-name | |
337 (file-name-nondirectory (car files)) target) | |
338 target)) | |
339 link) | |
340 (if (and (file-directory-p source) | |
341 (or (not no-dereference) | |
342 (not (file-symlink-p source))) | |
343 (not (memq func '(make-symbolic-link | |
344 add-name-to-file)))) | |
345 (if (and (eq func 'copy-file) | |
346 (not recursive)) | |
347 (eshell-error (format "%s: %s: omitting directory\n" | |
348 command (car files))) | |
349 (let (eshell-warn-dot-directories) | |
350 (if (and (not deep) | |
351 (eq func 'rename-file) | |
32446
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
352 (= (nth 11 (eshell-file-attributes |
29876 | 353 (file-name-directory |
354 (expand-file-name source)))) | |
32446
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
355 (nth 11 (eshell-file-attributes |
29876 | 356 (file-name-directory |
357 (expand-file-name target)))))) | |
358 (apply 'eshell-funcalln func source target args) | |
359 (unless (file-directory-p target) | |
360 (if verbose | |
361 (eshell-printn | |
362 (format "%s: making directory %s" | |
363 command target))) | |
364 (unless preview | |
365 (eshell-funcalln 'make-directory target))) | |
31241 | 366 (apply 'eshell-shuffle-files |
367 command action | |
368 (mapcar | |
369 (function | |
370 (lambda (file) | |
371 (concat source "/" file))) | |
372 (directory-files source)) | |
373 target func t args) | |
29876 | 374 (when (eq func 'rename-file) |
375 (if verbose | |
376 (eshell-printn | |
377 (format "%s: deleting directory %s" | |
378 command source))) | |
379 (unless preview | |
380 (eshell-funcalln 'delete-directory source)))))) | |
381 (if verbose | |
382 (eshell-printn (format "%s: %s -> %s" command | |
383 source target))) | |
384 (unless preview | |
385 (if (and no-dereference | |
386 (setq link (file-symlink-p source))) | |
387 (progn | |
388 (apply 'eshell-funcalln 'make-symbolic-link | |
389 link target args) | |
390 (if (eq func 'rename-file) | |
391 (if (and (file-directory-p source) | |
392 (not (file-symlink-p source))) | |
393 (eshell-funcalln 'delete-directory source) | |
394 (eshell-funcalln 'delete-file source)))) | |
395 (apply 'eshell-funcalln func source target args))))))) | |
396 (setq files (cdr files))))) | |
397 | |
398 (defun eshell-shorthand-tar-command (command args) | |
399 "Rewrite `cp -v dir a.tar.gz' to `tar cvzf a.tar.gz dir'." | |
400 (let* ((archive (car (last args))) | |
401 (tar-args | |
402 (cond ((string-match "z2" archive) "If") | |
403 ((string-match "gz" archive) "zf") | |
404 ((string-match "\\(az\\|Z\\)" archive) "Zf") | |
405 (t "f")))) | |
406 (if (file-exists-p archive) | |
407 (setq tar-args (concat "u" tar-args)) | |
408 (setq tar-args (concat "c" tar-args))) | |
409 (if verbose | |
410 (setq tar-args (concat "v" tar-args))) | |
411 (if (equal command "mv") | |
412 (setq tar-args (concat "--remove-files -" tar-args))) | |
413 ;; truncate the archive name from the arguments | |
414 (setcdr (last args 2) nil) | |
415 (throw 'eshell-replace-command | |
416 (eshell-parse-command | |
417 (format "tar %s %s" tar-args archive) args)))) | |
418 | |
419 ;; this is to avoid duplicating code... | |
420 (defmacro eshell-mvcp-template | |
421 (command action func query-var force-var &optional preserve) | |
422 `(if (and (string-match eshell-tar-regexp (car (last args))) | |
423 (or (> (length args) 2) | |
424 (and (file-directory-p (car args)) | |
425 (or (not no-dereference) | |
426 (not (file-symlink-p (car args))))))) | |
427 (eshell-shorthand-tar-command ,command 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
|
428 (let (target ange-cache) |
29876 | 429 (if (> (length args) 1) |
430 (progn | |
431 (setq target (car (last args))) | |
432 (setcdr (last args 2) nil)) | |
433 (setq args nil)) | |
434 (eshell-shuffle-files | |
435 ,command ,action args target ,func nil | |
436 ,@(append | |
437 `((if (and (or interactive | |
438 ,query-var) | |
439 (not force)) | |
440 1 (or force ,force-var))) | |
441 (if preserve | |
442 (list preserve))))) | |
443 nil)) | |
444 | |
445 (defun eshell/mv (&rest args) | |
446 "Implementation of mv in Lisp." | |
447 (eshell-eval-using-options | |
448 "mv" args | |
449 '((?f "force" nil force | |
450 "remove existing destinations, never prompt") | |
451 (?i "interactive" nil interactive | |
452 "request confirmation if target already exists") | |
453 (?n "preview" nil preview | |
454 "don't change anything on disk") | |
455 (?v "verbose" nil verbose | |
456 "explain what is being done") | |
457 (nil "help" nil nil "show this usage screen") | |
458 :external "mv" | |
459 :show-usage | |
460 :usage "[OPTION]... SOURCE DEST | |
461 or: mv [OPTION]... SOURCE... DIRECTORY | |
462 Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY. | |
463 \[OPTION] DIRECTORY...") | |
464 (let ((no-dereference t)) | |
465 (eshell-mvcp-template "mv" "moving" 'rename-file | |
466 eshell-mv-interactive-query | |
467 eshell-mv-overwrite-files)))) | |
468 | |
469 (defun eshell/cp (&rest args) | |
470 "Implementation of cp in Lisp." | |
471 (eshell-eval-using-options | |
472 "cp" args | |
473 '((?a "archive" nil archive | |
474 "same as -dpR") | |
475 (?d "no-dereference" nil no-dereference | |
476 "preserve links") | |
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 (?p "preserve" nil preserve | |
484 "preserve file attributes if possible") | |
485 (?R "recursive" nil recursive | |
486 "copy directories recursively") | |
487 (?v "verbose" nil verbose | |
488 "explain what is being done") | |
489 (nil "help" nil nil "show this usage screen") | |
490 :external "cp" | |
491 :show-usage | |
492 :usage "[OPTION]... SOURCE DEST | |
493 or: cp [OPTION]... SOURCE... DIRECTORY | |
494 Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.") | |
495 (if archive | |
496 (setq preserve t no-dereference t recursive t)) | |
497 (eshell-mvcp-template "cp" "copying" 'copy-file | |
498 eshell-cp-interactive-query | |
499 eshell-cp-overwrite-files preserve))) | |
500 | |
501 (defun eshell/ln (&rest args) | |
502 "Implementation of ln in Lisp." | |
503 (eshell-eval-using-options | |
504 "ln" args | |
505 '((?h "help" nil nil "show this usage screen") | |
506 (?s "symbolic" nil symbolic | |
507 "make symbolic links instead of hard links") | |
508 (?i "interactive" nil interactive "request confirmation if target already exists") | |
509 (?f "force" nil force "remove existing destinations, never prompt") | |
510 (?n "preview" nil preview | |
511 "don't change anything on disk") | |
512 (?v "verbose" nil verbose "explain what is being done") | |
513 :external "ln" | |
514 :show-usage | |
515 :usage "[OPTION]... TARGET [LINK_NAME] | |
516 or: ln [OPTION]... TARGET... DIRECTORY | |
517 Create a link to the specified TARGET with optional LINK_NAME. If there is | |
518 more than one TARGET, the last argument must be a directory; create links | |
519 in DIRECTORY to each TARGET. Create hard links by default, symbolic links | |
520 with '--symbolic'. When creating hard links, each TARGET must exist.") | |
32446
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
521 (let (target no-dereference ange-cache) |
29876 | 522 (if (> (length args) 1) |
523 (progn | |
524 (setq target (car (last args))) | |
525 (setcdr (last args 2) nil)) | |
526 (setq args nil)) | |
527 (eshell-shuffle-files "ln" "linking" args target | |
528 (if symbolic | |
529 'make-symbolic-link | |
530 'add-name-to-file) nil | |
531 (if (and (or interactive | |
532 eshell-ln-interactive-query) | |
533 (not force)) | |
534 1 (or force eshell-ln-overwrite-files)))) | |
535 nil)) | |
536 | |
537 (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
|
538 "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
|
539 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
|
540 symlink, then revert to the system's definition of cat." |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
541 (setq args (eshell-flatten-list args)) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
542 (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
|
543 (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
|
544 (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
|
545 (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
|
546 (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
|
547 '(?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
|
548 (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
|
549 (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
|
550 (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
|
551 (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
|
552 (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
|
553 (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
|
554 (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
|
555 (error "Eshell's `cat' cannot display one of the files given")))) |
29876 | 556 (eshell-init-print-buffer) |
557 (eshell-eval-using-options | |
558 "cat" args | |
559 '((?h "help" nil nil "show this usage screen") | |
560 :external "cat" | |
561 :show-usage | |
562 :usage "[OPTION] FILE... | |
563 Concatenate FILE(s), or standard input, to standard output.") | |
564 (eshell-for file args | |
565 (if (string= file "-") | |
566 (throw 'eshell-external | |
567 (eshell-external-command "cat" args)))) | |
568 (let ((curbuf (current-buffer))) | |
569 (eshell-for file args | |
570 (with-temp-buffer | |
571 (insert-file-contents file) | |
572 (goto-char (point-min)) | |
573 (while (not (eobp)) | |
574 (let ((str (buffer-substring | |
575 (point) (min (1+ (line-end-position)) | |
576 (point-max))))) | |
577 (with-current-buffer curbuf | |
578 (eshell-buffered-print str))) | |
579 (forward-line))))) | |
580 (eshell-flush) | |
581 ;; if the file does not end in a newline, do not emit one | |
582 (setq eshell-ensure-newline-p nil)))) | |
583 | |
584 ;; special front-end functions for compilation-mode buffers | |
585 | |
586 (defun eshell/make (&rest args) | |
587 "Use `compile' to do background makes." | |
588 (if (and eshell-current-subjob-p | |
589 (eshell-interactive-output-p)) | |
590 (let ((compilation-process-setup-function | |
591 (list 'lambda nil | |
592 (list 'setq 'process-environment | |
593 (list 'quote (eshell-copy-environment)))))) | |
594 (compile (concat "make " (eshell-flatten-and-stringify args)))) | |
595 (throw 'eshell-replace-command | |
31241 | 596 (eshell-parse-command "*make" (eshell-flatten-list args))))) |
29876 | 597 |
598 (defun eshell-occur-mode-goto-occurrence () | |
599 "Go to the occurrence the current line describes." | |
600 (interactive) | |
601 (let ((pos (occur-mode-find-occurrence))) | |
602 (pop-to-buffer (marker-buffer pos)) | |
603 (goto-char (marker-position pos)))) | |
604 | |
605 (defun eshell-occur-mode-mouse-goto (event) | |
606 "In Occur mode, go to the occurrence whose line you click on." | |
607 (interactive "e") | |
608 (let (buffer pos) | |
609 (save-excursion | |
610 (set-buffer (window-buffer (posn-window (event-end event)))) | |
611 (save-excursion | |
612 (goto-char (posn-point (event-end event))) | |
613 (setq pos (occur-mode-find-occurrence)) | |
614 (setq buffer occur-buffer))) | |
615 (pop-to-buffer (marker-buffer pos)) | |
616 (goto-char (marker-position pos)))) | |
617 | |
618 (defun eshell-poor-mans-grep (args) | |
619 "A poor version of grep that opens every file and uses `occur'. | |
620 This eats up memory, since it leaves the buffers open (to speed future | |
621 searches), and it's very slow. But, if your system has no grep | |
622 available..." | |
623 (save-selected-window | |
624 (let ((default-dir default-directory)) | |
625 (with-current-buffer (get-buffer-create "*grep*") | |
626 (let ((inhibit-read-only t) | |
627 (default-directory default-dir)) | |
628 (erase-buffer) | |
629 (occur-mode) | |
630 (let ((files (eshell-flatten-list (cdr args))) | |
631 (inhibit-redisplay t) | |
632 string) | |
633 (when (car args) | |
634 (if (get-buffer "*Occur*") | |
635 (kill-buffer (get-buffer "*Occur*"))) | |
636 (setq string nil) | |
637 (while files | |
638 (with-current-buffer (find-file-noselect (car files)) | |
639 (save-excursion | |
640 (ignore-errors | |
641 (occur (car args)))) | |
642 (if (get-buffer "*Occur*") | |
643 (with-current-buffer (get-buffer "*Occur*") | |
644 (setq string (buffer-string)) | |
645 (kill-buffer (current-buffer))))) | |
646 (if string (insert string)) | |
647 (setq string nil | |
648 files (cdr files))))) | |
649 (setq occur-buffer (current-buffer)) | |
650 (local-set-key [mouse-2] 'eshell-occur-mode-mouse-goto) | |
651 (local-set-key [(control ?c) (control ?c)] | |
652 'eshell-occur-mode-goto-occurrence) | |
653 (local-set-key [(control ?m)] | |
654 'eshell-occur-mode-goto-occurrence) | |
655 (local-set-key [return] 'eshell-occur-mode-goto-occurrence) | |
656 (pop-to-buffer (current-buffer) t) | |
657 (goto-char (point-min)) | |
658 (resize-temp-buffer-window)))))) | |
659 | |
660 (defun eshell-grep (command args &optional maybe-use-occur) | |
661 "Generic service function for the various grep aliases. | |
662 It calls Emacs' grep utility if the command is not redirecting output, | |
663 and if it's not part of a command pipeline. Otherwise, it calls the | |
664 external command." | |
665 (if (and maybe-use-occur eshell-no-grep-available) | |
666 (eshell-poor-mans-grep args) | |
667 (if (or eshell-plain-grep-behavior | |
668 (not (and (eshell-interactive-output-p) | |
669 (not eshell-in-pipeline-p) | |
670 (not eshell-in-subcommand-p)))) | |
671 (throw 'eshell-replace-command | |
31241 | 672 (eshell-parse-command (concat "*" command) |
673 (eshell-flatten-list args))) | |
29876 | 674 (let* ((compilation-process-setup-function |
675 (list 'lambda nil | |
676 (list 'setq 'process-environment | |
677 (list 'quote (eshell-copy-environment))))) | |
678 (args (mapconcat 'identity | |
679 (mapcar 'shell-quote-argument | |
680 (eshell-flatten-list args)) | |
681 " ")) | |
682 (cmd (progn | |
683 (set-text-properties 0 (length args) | |
684 '(invisible t) args) | |
685 (format "%s -n %s" command args))) | |
686 compilation-scroll-output) | |
687 (grep cmd))))) | |
688 | |
689 (defun eshell/grep (&rest args) | |
690 "Use Emacs grep facility instead of calling external grep." | |
691 (eshell-grep "grep" args t)) | |
692 | |
693 (defun eshell/egrep (&rest args) | |
694 "Use Emacs grep facility instead of calling external egrep." | |
695 (eshell-grep "egrep" args t)) | |
696 | |
697 (defun eshell/fgrep (&rest args) | |
698 "Use Emacs grep facility instead of calling external fgrep." | |
699 (eshell-grep "fgrep" args t)) | |
700 | |
701 (defun eshell/agrep (&rest args) | |
702 "Use Emacs grep facility instead of calling external agrep." | |
703 (eshell-grep "agrep" args)) | |
704 | |
705 (defun eshell/glimpse (&rest args) | |
706 "Use Emacs grep facility instead of calling external glimpse." | |
707 (let (null-device) | |
708 (eshell-grep "glimpse" (append '("-z" "-y") args)))) | |
709 | |
710 ;; completions rules for some common UNIX commands | |
711 | |
712 (defsubst eshell-complete-hostname () | |
713 "Complete a command that wants a hostname for an argument." | |
714 (pcomplete-here (eshell-read-host-names))) | |
715 | |
716 (defun eshell-complete-host-reference () | |
717 "If there is a host reference, complete it." | |
718 (let ((arg (pcomplete-actual-arg)) | |
719 index) | |
720 (when (setq index (string-match "@[a-z.]*\\'" arg)) | |
721 (setq pcomplete-stub (substring arg (1+ index)) | |
722 pcomplete-last-completion-raw t) | |
723 (throw 'pcomplete-completions (eshell-read-host-names))))) | |
724 | |
725 (defalias 'pcomplete/ftp 'eshell-complete-hostname) | |
726 (defalias 'pcomplete/ncftp 'eshell-complete-hostname) | |
727 (defalias 'pcomplete/ping 'eshell-complete-hostname) | |
728 (defalias 'pcomplete/rlogin 'eshell-complete-hostname) | |
729 | |
730 (defun pcomplete/telnet () | |
731 (require 'pcmpl-unix) | |
732 (pcomplete-opt "xl(pcmpl-unix-user-names)") | |
733 (eshell-complete-hostname)) | |
734 | |
735 (defun pcomplete/rsh () | |
736 "Complete `rsh', which, after the user and hostname, is like xargs." | |
737 (require 'pcmpl-unix) | |
738 (pcomplete-opt "l(pcmpl-unix-user-names)") | |
739 (eshell-complete-hostname) | |
740 (pcomplete-here (funcall pcomplete-command-completion-function)) | |
741 (funcall (or (pcomplete-find-completion-function (pcomplete-arg 1)) | |
742 pcomplete-default-completion-function))) | |
743 | |
744 (defalias 'pcomplete/ssh 'pcomplete/rsh) | |
745 | |
746 (eval-when-compile | |
747 (defvar block-size) | |
748 (defvar by-bytes) | |
749 (defvar dereference-links) | |
750 (defvar grand-total) | |
751 (defvar human-readable) | |
752 (defvar max-depth) | |
753 (defvar only-one-filesystem) | |
754 (defvar show-all)) | |
755 | |
756 (defsubst eshell-du-size-string (size) | |
757 (let* ((str (eshell-printable-size size human-readable block-size t)) | |
758 (len (length str))) | |
759 (concat str (if (< len 8) | |
760 (make-string (- 8 len) ? ))))) | |
761 | |
762 (defun eshell-du-sum-directory (path depth) | |
763 "Summarize PATH, and its member directories." | |
764 (let ((entries (eshell-directory-files-and-attributes path)) | |
765 (size 0.0)) | |
766 (while entries | |
767 (unless (string-match "\\`\\.\\.?\\'" (caar entries)) | |
768 (let* ((entry (concat path (char-to-string directory-sep-char) | |
769 (caar entries))) | |
770 (symlink (and (stringp (cadr (car entries))) | |
771 (cadr (car entries))))) | |
772 (unless (or (and symlink (not dereference-links)) | |
773 (and only-one-filesystem | |
31241 | 774 (/= only-one-filesystem |
775 (nth 12 (car entries))))) | |
29876 | 776 (if symlink |
777 (setq entry symlink)) | |
778 (setq size | |
779 (+ size | |
780 (if (eq t (cadr (car entries))) | |
781 (eshell-du-sum-directory entry (1+ depth)) | |
782 (let ((file-size (nth 8 (car entries)))) | |
783 (prog1 | |
784 file-size | |
785 (if show-all | |
786 (eshell-print | |
787 (concat (eshell-du-size-string file-size) | |
788 entry "\n"))))))))))) | |
789 (setq entries (cdr entries))) | |
790 (if (or (not max-depth) | |
791 (= depth max-depth) | |
792 (= depth 0)) | |
793 (eshell-print (concat (eshell-du-size-string size) | |
794 (directory-file-name path) "\n"))) | |
795 size)) | |
796 | |
797 (defun eshell/du (&rest args) | |
31241 | 798 "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
|
799 (setq args (if args |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
800 (eshell-flatten-list args) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
801 '("."))) |
aab90b31807c
Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents:
31241
diff
changeset
|
802 (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
|
803 (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
|
804 (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
|
805 (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
|
806 (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
|
807 '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
|
808 '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
|
809 (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
|
810 (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
|
811 (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
|
812 (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
|
813 "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
|
814 '((?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
|
815 "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
|
816 (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
|
817 "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
|
818 (?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
|
819 "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
|
820 (?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
|
821 "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
|
822 (?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
|
823 "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
|
824 (?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
|
825 "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
|
826 (?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
|
827 "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
|
828 (?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
|
829 "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
|
830 (?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
|
831 "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
|
832 (?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
|
833 "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
|
834 (?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
|
835 "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
|
836 (?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
|
837 "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
|
838 (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
|
839 "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
|
840 :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
|
841 :usage "[OPTION]... FILE... |
29876 | 842 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
|
843 (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
|
844 (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
|
845 (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
|
846 (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
|
847 ;; 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
|
848 (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
|
849 (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
|
850 (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
|
851 (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
|
852 (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
|
853 (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
|
854 (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
|
855 (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
|
856 (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
|
857 (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
|
858 (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
|
859 (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
|
860 (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
|
861 "total\n")))))))) |
29876 | 862 |
863 (defvar eshell-time-start nil) | |
864 | |
865 (defun eshell-show-elapsed-time () | |
866 (let ((elapsed (format "%.3f secs\n" | |
867 (- (eshell-time-to-seconds (current-time)) | |
868 eshell-time-start)))) | |
869 (set-text-properties 0 (length elapsed) '(face bold) elapsed) | |
870 (eshell-interactive-print elapsed)) | |
871 (remove-hook 'eshell-post-command-hook 'eshell-show-elapsed-time t)) | |
872 | |
873 (defun eshell/time (&rest args) | |
874 "Implementation of \"time\" in Lisp." | |
875 (let ((time-args (copy-alist args)) | |
876 (continue t) | |
877 last-arg) | |
878 (while (and continue args) | |
879 (if (not (string-match "^-" (car args))) | |
880 (progn | |
881 (if last-arg | |
882 (setcdr last-arg nil) | |
883 (setq args '(""))) | |
884 (setq continue nil)) | |
885 (setq last-arg args | |
886 args (cdr args)))) | |
887 (eshell-eval-using-options | |
888 "time" args | |
889 '((?h "help" nil nil "show this usage screen") | |
890 :external "time" | |
891 :show-usage | |
892 :usage "COMMAND... | |
893 Show wall-clock time elapsed during execution of COMMAND.") | |
894 (setq eshell-time-start (eshell-time-to-seconds (current-time))) | |
895 (add-hook 'eshell-post-command-hook 'eshell-show-elapsed-time nil t) | |
896 ;; after setting | |
897 (throw 'eshell-replace-command | |
898 (eshell-parse-command (car time-args) (cdr time-args)))))) | |
899 | |
900 (defalias 'eshell/whoami 'user-login-name) | |
901 | |
902 (defvar eshell-diff-window-config nil) | |
903 | |
904 (defun eshell-diff-quit () | |
905 "Restore the window configuration previous to diff'ing." | |
906 (interactive) | |
907 (if eshell-diff-window-config | |
908 (set-window-configuration eshell-diff-window-config))) | |
909 | |
910 (defun eshell/diff (&rest args) | |
911 "Alias \"diff\" to call Emacs `diff' function." | |
31241 | 912 (let ((orig-args (eshell-flatten-list args))) |
913 (if (or eshell-plain-diff-behavior | |
914 (not (and (eshell-interactive-output-p) | |
915 (not eshell-in-pipeline-p) | |
916 (not eshell-in-subcommand-p)))) | |
917 (throw 'eshell-replace-command | |
918 (eshell-parse-command "*diff" orig-args)) | |
919 (setq args (eshell-copy-list orig-args)) | |
920 (if (< (length args) 2) | |
921 (throw 'eshell-replace-command | |
922 (eshell-parse-command "*diff" orig-args))) | |
923 (let ((old (car (last args 2))) | |
924 (new (car (last args))) | |
925 (config (current-window-configuration))) | |
926 (if (= (length args) 2) | |
927 (setq args nil) | |
928 (setcdr (last args 3) nil)) | |
929 (with-current-buffer | |
930 (condition-case err | |
931 (diff old new (eshell-flatten-and-stringify args)) | |
932 (error | |
933 (throw 'eshell-replace-command | |
934 (eshell-parse-command "*diff" orig-args)))) | |
935 (when (fboundp 'diff-mode) | |
936 (diff-mode) | |
937 (set (make-local-variable 'eshell-diff-window-config) config) | |
938 (local-set-key [?q] 'eshell-diff-quit) | |
939 (if (fboundp 'turn-on-font-lock-if-enabled) | |
940 (turn-on-font-lock-if-enabled)))) | |
941 (other-window 1) | |
942 (goto-char (point-min)) | |
943 nil)))) | |
29876 | 944 |
945 (defun eshell/locate (&rest args) | |
946 "Alias \"locate\" to call Emacs `locate' function." | |
947 (if (or eshell-plain-locate-behavior | |
948 (not (and (eshell-interactive-output-p) | |
949 (not eshell-in-pipeline-p) | |
950 (not eshell-in-subcommand-p))) | |
951 (and (stringp (car args)) | |
952 (string-match "^-" (car args)))) | |
953 (throw 'eshell-replace-command | |
31241 | 954 (eshell-parse-command "*locate" (eshell-flatten-list args))) |
29876 | 955 (save-selected-window |
956 (let ((locate-history-list (list (car args)))) | |
957 (locate-with-filter (car args) (cadr args)))))) | |
958 | |
959 (defun eshell/occur (&rest args) | |
960 "Alias \"occur\" to call Emacs `occur' function." | |
961 (let ((inhibit-read-only t)) | |
962 (if args | |
963 (error "usage: occur: (REGEXP)") | |
964 (occur (car args))))) | |
965 | |
966 ;;; Code: | |
967 | |
968 ;;; em-unix.el ends here |