aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/eshell
diff options
context:
space:
mode:
authorKenichi Handa2013-04-05 23:17:55 +0900
committerKenichi Handa2013-04-05 23:17:55 +0900
commitb7a6f9f7919b7fc0871ae768b58f8e746aa7dd9f (patch)
treef32c8cce416e346d2953f063a0f22e95382cf57e /lisp/eshell
parent251e91474c91e16b101502c2ed7c05fc13e4ecea (diff)
parent73931ad14ad7a51d91f10b19ae9ca8cadb256916 (diff)
downloademacs-b7a6f9f7919b7fc0871ae768b58f8e746aa7dd9f.tar.gz
emacs-b7a6f9f7919b7fc0871ae768b58f8e746aa7dd9f.zip
merge trunk
Diffstat (limited to 'lisp/eshell')
-rw-r--r--lisp/eshell/em-prompt.el1
-rw-r--r--lisp/eshell/em-tramp.el143
-rw-r--r--lisp/eshell/em-unix.el81
3 files changed, 145 insertions, 80 deletions
diff --git a/lisp/eshell/em-prompt.el b/lisp/eshell/em-prompt.el
index c1c4d4730f9..c5429c59bd6 100644
--- a/lisp/eshell/em-prompt.el
+++ b/lisp/eshell/em-prompt.el
@@ -122,6 +122,7 @@ arriving, or after."
122 (add-text-properties 0 (length prompt) 122 (add-text-properties 0 (length prompt)
123 '(read-only t 123 '(read-only t
124 face eshell-prompt 124 face eshell-prompt
125 front-sticky (face read-only)
125 rear-nonsticky (face read-only)) 126 rear-nonsticky (face read-only))
126 prompt)) 127 prompt))
127 (eshell-interactive-print prompt))) 128 (eshell-interactive-print prompt)))
diff --git a/lisp/eshell/em-tramp.el b/lisp/eshell/em-tramp.el
new file mode 100644
index 00000000000..c60d0e6395f
--- /dev/null
+++ b/lisp/eshell/em-tramp.el
@@ -0,0 +1,143 @@
1;;; em-tramp.el --- Eshell features that require TRAMP
2
3;; Copyright (C) 1999-2013 Free Software Foundation, Inc.
4
5;; Author: Aidan Gauland <aidalgol@no8wireless.co.nz>
6
7;; This file is part of GNU Emacs.
8
9;; GNU Emacs is free software: you can redistribute it and/or modify
10;; it under the terms of the GNU General Public License as published by
11;; the Free Software Foundation, either version 3 of the License, or
12;; (at your option) any later version.
13
14;; GNU Emacs is distributed in the hope that it will be useful,
15;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17;; GNU General Public License for more details.
18
19;; You should have received a copy of the GNU General Public License
20;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
21
22;;; Commentary:
23
24;; Eshell features that require TRAMP.
25
26;;; Code:
27
28(eval-when-compile
29 (require 'esh-mode)
30 (require 'eshell)
31 (require 'tramp))
32
33(require 'esh-util)
34
35;;;###autoload
36(progn
37 (defgroup eshell-tramp nil
38 "This module defines commands that use TRAMP in a way that is
39 not transparent to the user. So far, this includes only the
40 built-in su and sudo commands, which are not compatible with
41 the full, external su and sudo commands, and require the user
42 to understand how to use the TRAMP sudo method."
43 :tag "TRAMP Eshell features"
44 :group 'eshell-module))
45
46(defun eshell-tramp-initialize ()
47 "Initialize the TRAMP-using commands code."
48 (when (eshell-using-module 'eshell-cmpl)
49 (add-hook 'pcomplete-try-first-hook
50 'eshell-complete-host-reference nil t))
51 (make-local-variable 'eshell-complex-commands)
52 (setq eshell-complex-commands
53 (append '("su" "sudo")
54 eshell-complex-commands)))
55
56(defun eshell/su (&rest args)
57 "Alias \"su\" to call TRAMP.
58
59Uses the system su through TRAMP's su method."
60 (setq args (eshell-stringify-list (eshell-flatten-list args)))
61 (let ((orig-args (copy-tree args)))
62 (eshell-eval-using-options
63 "su" args
64 '((?h "help" nil nil "show this usage screen")
65 (?l "login" nil login "provide a login environment")
66 (? nil nil login "provide a login environment")
67 :usage "[- | -l | --login] [USER]
68Become another USER during a login session.")
69 (throw 'eshell-replace-command
70 (let ((user "root")
71 (host (or (file-remote-p default-directory 'host)
72 "localhost"))
73 (dir (or (file-remote-p default-directory 'localname)
74 (expand-file-name default-directory)))
75 (prefix (file-remote-p default-directory)))
76 (dolist (arg args)
77 (if (string-equal arg "-") (setq login t) (setq user arg)))
78 ;; `eshell-eval-using-options' does not handle "-".
79 (if (member "-" orig-args) (setq login t))
80 (if login (setq dir "~/"))
81 (if (and prefix
82 (or
83 (not (string-equal
84 "su" (file-remote-p default-directory 'method)))
85 (not (string-equal
86 user (file-remote-p default-directory 'user)))))
87 (eshell-parse-command
88 "cd" (list (format "%s|su:%s@%s:%s"
89 (substring prefix 0 -1) user host dir)))
90 (eshell-parse-command
91 "cd" (list (format "/su:%s@%s:%s" user host dir)))))))))
92
93(put 'eshell/su 'eshell-no-numeric-conversions t)
94
95(defun eshell/sudo (&rest args)
96 "Alias \"sudo\" to call Tramp.
97
98Uses the system sudo through TRAMP's sudo method."
99 (setq args (eshell-stringify-list (eshell-flatten-list args)))
100 (let ((orig-args (copy-tree args)))
101 (eshell-eval-using-options
102 "sudo" args
103 '((?h "help" nil nil "show this usage screen")
104 (?u "user" t user "execute a command as another USER")
105 :show-usage
106 :usage "[(-u | --user) USER] COMMAND
107Execute a COMMAND as the superuser or another USER.")
108 (throw 'eshell-external
109 (let ((user (or user "root"))
110 (host (or (file-remote-p default-directory 'host)
111 "localhost"))
112 (dir (or (file-remote-p default-directory 'localname)
113 (expand-file-name default-directory)))
114 (prefix (file-remote-p default-directory)))
115 ;; `eshell-eval-using-options' reads options of COMMAND.
116 (while (and (stringp (car orig-args))
117 (member (car orig-args) '("-u" "--user")))
118 (setq orig-args (cddr orig-args)))
119 (let ((default-directory
120 (if (and prefix
121 (or
122 (not
123 (string-equal
124 "sudo"
125 (file-remote-p default-directory 'method)))
126 (not
127 (string-equal
128 user
129 (file-remote-p default-directory 'user)))))
130 (format "%s|sudo:%s@%s:%s"
131 (substring prefix 0 -1) user host dir)
132 (format "/sudo:%s@%s:%s" user host dir))))
133 (eshell-named-command (car orig-args) (cdr orig-args))))))))
134
135(put 'eshell/sudo 'eshell-no-numeric-conversions t)
136
137(provide 'em-tramp)
138
139;; Local Variables:
140;; generated-autoload-file: "esh-groups.el"
141;; End:
142
143;;; em-tramp.el ends here
diff --git a/lisp/eshell/em-unix.el b/lisp/eshell/em-unix.el
index 94508d71592..60caf38710a 100644
--- a/lisp/eshell/em-unix.el
+++ b/lisp/eshell/em-unix.el
@@ -148,7 +148,7 @@ Otherwise, Emacs will attempt to use rsh to invoke du on the remote machine."
148 (make-local-variable 'eshell-complex-commands) 148 (make-local-variable 'eshell-complex-commands)
149 (setq eshell-complex-commands 149 (setq eshell-complex-commands
150 (append '("grep" "egrep" "fgrep" "agrep" "glimpse" "locate" 150 (append '("grep" "egrep" "fgrep" "agrep" "glimpse" "locate"
151 "cat" "time" "cp" "mv" "make" "du" "diff" "su" "sudo") 151 "cat" "time" "cp" "mv" "make" "du" "diff")
152 eshell-complex-commands))) 152 eshell-complex-commands)))
153 153
154(defalias 'eshell/date 'current-time-string) 154(defalias 'eshell/date 'current-time-string)
@@ -1038,85 +1038,6 @@ Show wall-clock time elapsed during execution of COMMAND.")
1038 1038
1039(put 'eshell/occur 'eshell-no-numeric-conversions t) 1039(put 'eshell/occur 'eshell-no-numeric-conversions t)
1040 1040
1041(defun eshell/su (&rest args)
1042 "Alias \"su\" to call Tramp."
1043 (require 'tramp)
1044 (setq args (eshell-stringify-list (eshell-flatten-list args)))
1045 (let ((orig-args (copy-tree args)))
1046 (eshell-eval-using-options
1047 "su" args
1048 '((?h "help" nil nil "show this usage screen")
1049 (?l "login" nil login "provide a login environment")
1050 (? nil nil login "provide a login environment")
1051 :usage "[- | -l | --login] [USER]
1052Become another USER during a login session.")
1053 (throw 'eshell-replace-command
1054 (let ((user "root")
1055 (host (or (file-remote-p default-directory 'host)
1056 "localhost"))
1057 (dir (or (file-remote-p default-directory 'localname)
1058 (expand-file-name default-directory)))
1059 (prefix (file-remote-p default-directory)))
1060 (dolist (arg args)
1061 (if (string-equal arg "-") (setq login t) (setq user arg)))
1062 ;; `eshell-eval-using-options' does not handle "-".
1063 (if (member "-" orig-args) (setq login t))
1064 (if login (setq dir "~/"))
1065 (if (and prefix
1066 (or
1067 (not (string-equal
1068 "su" (file-remote-p default-directory 'method)))
1069 (not (string-equal
1070 user (file-remote-p default-directory 'user)))))
1071 (eshell-parse-command
1072 "cd" (list (format "%s|su:%s@%s:%s"
1073 (substring prefix 0 -1) user host dir)))
1074 (eshell-parse-command
1075 "cd" (list (format "/su:%s@%s:%s" user host dir)))))))))
1076
1077(put 'eshell/su 'eshell-no-numeric-conversions t)
1078
1079(defun eshell/sudo (&rest args)
1080 "Alias \"sudo\" to call Tramp."
1081 (require 'tramp)
1082 (setq args (eshell-stringify-list (eshell-flatten-list args)))
1083 (let ((orig-args (copy-tree args)))
1084 (eshell-eval-using-options
1085 "sudo" args
1086 '((?h "help" nil nil "show this usage screen")
1087 (?u "user" t user "execute a command as another USER")
1088 :show-usage
1089 :usage "[(-u | --user) USER] COMMAND
1090Execute a COMMAND as the superuser or another USER.")
1091 (throw 'eshell-external
1092 (let ((user (or user "root"))
1093 (host (or (file-remote-p default-directory 'host)
1094 "localhost"))
1095 (dir (or (file-remote-p default-directory 'localname)
1096 (expand-file-name default-directory)))
1097 (prefix (file-remote-p default-directory)))
1098 ;; `eshell-eval-using-options' reads options of COMMAND.
1099 (while (and (stringp (car orig-args))
1100 (member (car orig-args) '("-u" "--user")))
1101 (setq orig-args (cddr orig-args)))
1102 (let ((default-directory
1103 (if (and prefix
1104 (or
1105 (not
1106 (string-equal
1107 "sudo"
1108 (file-remote-p default-directory 'method)))
1109 (not
1110 (string-equal
1111 user
1112 (file-remote-p default-directory 'user)))))
1113 (format "%s|sudo:%s@%s:%s"
1114 (substring prefix 0 -1) user host dir)
1115 (format "/sudo:%s@%s:%s" user host dir))))
1116 (eshell-named-command (car orig-args) (cdr orig-args))))))))
1117
1118(put 'eshell/sudo 'eshell-no-numeric-conversions t)
1119
1120(provide 'em-unix) 1041(provide 'em-unix)
1121 1042
1122;; Local Variables: 1043;; Local Variables: