summaryrefslogtreecommitdiff
path: root/lisp/eshell
diff options
context:
space:
mode:
authorMichael Albinus <michael.albinus@gmx.de>2009-12-03 11:34:11 +0000
committerMichael Albinus <michael.albinus@gmx.de>2009-12-03 11:34:11 +0000
commita09dc9bf9c3c40638d3fe6bf1905de05d7dac6fb (patch)
tree8f271dddbc5629879fa1e0c6aa4dfb84dbaef5ab /lisp/eshell
parent228fb9b59ea7328f34c799835ae6dd9310a49f25 (diff)
downloademacs-a09dc9bf9c3c40638d3fe6bf1905de05d7dac6fb.tar.gz
Cleanup.
* eshell/em-unix.el (top): Require 'esh-opt and 'pcomplete. (eshell/su, eshell/sudo): Require 'tramp. Fix problems reading arguments. Expand `default-directory'. * net/tramp.el (tramp-handle-file-remote-p): Expand FILENAME for the benefit of returning an expanded localname. (tramp-tramp-file-p): Handle the case NAME is not a string.
Diffstat (limited to 'lisp/eshell')
-rw-r--r--lisp/eshell/em-unix.el44
1 files changed, 30 insertions, 14 deletions
diff --git a/lisp/eshell/em-unix.el b/lisp/eshell/em-unix.el
index dfd72f6b2ac..7de13d0b8ac 100644
--- a/lisp/eshell/em-unix.el
+++ b/lisp/eshell/em-unix.el
@@ -37,6 +37,8 @@
;;; Code:
(require 'eshell)
+(require 'esh-opt)
+(require 'pcomplete)
;;;###autoload
(eshell-defgroup eshell-unix nil
@@ -1048,10 +1050,11 @@ Show wall-clock time elapsed during execution of COMMAND.")
(defun eshell/su (&rest args)
"Alias \"su\" to call Tramp."
+ (require 'tramp)
(setq args (eshell-stringify-list (eshell-flatten-list args)))
- (let (login)
+ (let ((orig-args (copy-tree args)))
(eshell-eval-using-options
- "sudo" args
+ "su" args
'((?h "help" nil nil "show this usage screen")
(?l "login" nil login "provide a login environment")
(? nil nil login "provide a login environment")
@@ -1062,13 +1065,18 @@ Become another USER during a login session.")
(host (or (file-remote-p default-directory 'host)
"localhost"))
(dir (or (file-remote-p default-directory 'localname)
- default-directory)))
+ (expand-file-name default-directory))))
(eshell-for arg args
(if (string-equal arg "-") (setq login t) (setq user arg)))
+ ;; `eshell-eval-using-options' does not handle "-".
+ (if (member "-" orig-args) (setq login t))
(if login (setq dir "~/"))
(if (and (file-remote-p default-directory)
- (not (string-equal
- user (file-remote-p default-directory 'user))))
+ (or
+ (not (string-equal
+ "su" (file-remote-p default-directory 'method)))
+ (not (string-equal
+ user (file-remote-p default-directory 'user)))))
(add-to-list
'tramp-default-proxies-alist
(list host user (file-remote-p default-directory))))
@@ -1079,8 +1087,9 @@ Become another USER during a login session.")
(defun eshell/sudo (&rest args)
"Alias \"sudo\" to call Tramp."
+ (require 'tramp)
(setq args (eshell-stringify-list (eshell-flatten-list args)))
- (let (user)
+ (let ((orig-args (copy-tree args)))
(eshell-eval-using-options
"sudo" args
'((?h "help" nil nil "show this usage screen")
@@ -1089,19 +1098,26 @@ Become another USER during a login session.")
:usage "[(-u | --user) USER] COMMAND
Execute a COMMAND as the superuser or another USER.")
(throw 'eshell-external
- (let* ((user (or user "root"))
- (host (or (file-remote-p default-directory 'host)
- "localhost"))
- (dir (or (file-remote-p default-directory 'localname)
- default-directory)))
+ (let ((user (or user "root"))
+ (host (or (file-remote-p default-directory 'host)
+ "localhost"))
+ (dir (or (file-remote-p default-directory 'localname)
+ (expand-file-name default-directory))))
+ ;; `eshell-eval-using-options' reads options of COMMAND.
+ (while (and (stringp (car orig-args))
+ (member (car orig-args) '("-u" "--user")))
+ (setq orig-args (cddr orig-args)))
(if (and (file-remote-p default-directory)
- (not (string-equal
- user (file-remote-p default-directory 'user))))
+ (or
+ (not (string-equal
+ "sudo" (file-remote-p default-directory 'method)))
+ (not (string-equal
+ user (file-remote-p default-directory 'user)))))
(add-to-list
'tramp-default-proxies-alist
(list host user (file-remote-p default-directory))))
(let ((default-directory (format "/sudo:%s@%s:%s" user host dir)))
- (eshell-named-command (car args) (cdr args))))))))
+ (eshell-named-command (car orig-args) (cdr orig-args))))))))
(put 'eshell/sudo 'eshell-no-numeric-conversions t)