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