annotate lisp/eshell/em-unix.el @ 111540:ca297dbe1d56

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