[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] emacs/lisp/eshell em-unix.el
From: |
Michael Albinus |
Subject: |
[Emacs-diffs] emacs/lisp/eshell em-unix.el |
Date: |
Fri, 27 Nov 2009 16:28:42 +0000 |
CVSROOT: /sources/emacs
Module name: emacs
Changes by: Michael Albinus <albinus> 09/11/27 16:28:42
Modified files:
lisp/eshell : em-unix.el
Log message:
* eshell/em-unix.el (eshell/su, eshell/sudo): New defuns,
providing a Tramp related implementation of "su" and "sudo".
(eshell-unix-initialize): Add "su" and "sudo".
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/emacs/lisp/eshell/em-unix.el?cvsroot=emacs&r1=1.46&r2=1.47
Patches:
Index: em-unix.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/eshell/em-unix.el,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -b -r1.46 -r1.47
--- em-unix.el 24 Nov 2009 10:25:58 -0000 1.46
+++ em-unix.el 27 Nov 2009 16:28:42 -0000 1.47
@@ -145,7 +145,7 @@
(make-local-variable 'eshell-complex-commands)
(setq eshell-complex-commands
(append '("grep" "egrep" "fgrep" "agrep" "glimpse" "locate"
- "cat" "time" "cp" "mv" "make" "du" "diff")
+ "cat" "time" "cp" "mv" "make" "du" "diff" "su" "sudo")
eshell-complex-commands)))
(defalias 'eshell/date 'current-time-string)
@@ -1041,6 +1041,66 @@
(put 'eshell/occur 'eshell-no-numeric-conversions t)
+;; Pacify the byte-compiler.
+(defvar tramp-default-proxies-alist)
+
+(defun eshell/su (&rest args)
+ "Alias \"su\" to call Tramp."
+ (let ((-login (member "-" args)) ;; not handled by
`eshell-eval-using-options'
+ login)
+ (eshell-eval-using-options
+ "sudo" args
+ '((?h "help" nil nil "show this usage screen")
+ (?l "login" nil login "provide a login environment")
+ (? nil nil login "provide a login environment")
+ :usage "[- | -l | --login] [USER]
+Become another USER during a login session.")
+ (throw 'eshell-replace-command
+ (let ((user "root")
+ (host (or (file-remote-p default-directory 'host)
+ "localhost"))
+ (dir (or (file-remote-p default-directory 'localname)
+ default-directory)))
+ (if (or login -login) (setq dir "~/"))
+ (if (stringp (car args)) (setq user (car args)))
+ (if (and (file-remote-p default-directory)
+ (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))))
+ (eshell-parse-command
+ "eshell/cd" (list (format "/su:address@hidden:%s" user host
dir))))))))
+
+(put 'eshell/su 'eshell-no-numeric-conversions t)
+
+(defun eshell/sudo (&rest args)
+ "Alias \"sudo\" to call Tramp."
+ (let (user)
+ (eshell-eval-using-options
+ "sudo" args
+ '((?h "help" nil nil "show this usage screen")
+ (?u "user" t user "execute a command as another USER")
+ :show-usage
+ :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))
+ (default-directory (format "/sudo:address@hidden:%s" user
host dir)))
+ (if (and (file-remote-p default-directory)
+ (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))))
+ (eshell-named-command (car args) (cdr args)))))))
+
+(put 'eshell/sudo 'eshell-no-numeric-conversions t)
+
(provide 'em-unix)
;; Local Variables:
- [Emacs-diffs] emacs/lisp/eshell em-unix.el,
Michael Albinus <=