diff options
| author | Michael Albinus | 2009-11-27 16:29:03 +0000 |
|---|---|---|
| committer | Michael Albinus | 2009-11-27 16:29:03 +0000 |
| commit | 3ba30eb8377c8b895ce75ef25057cf4304d7cd2a (patch) | |
| tree | 73ba673b3e49b3e1403b0433b6b845083469ef1b | |
| parent | c525b3f2d298a50fd86b0bc3bf5d07ed4301dfda (diff) | |
| download | emacs-3ba30eb8377c8b895ce75ef25057cf4304d7cd2a.tar.gz emacs-3ba30eb8377c8b895ce75ef25057cf4304d7cd2a.zip | |
* 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".
| -rw-r--r-- | lisp/ChangeLog | 6 | ||||
| -rw-r--r-- | lisp/eshell/em-unix.el | 62 |
2 files changed, 67 insertions, 1 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 7227f11add3..6e719cfe520 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2009-11-27 Michael Albinus <michael.albinus@gmx.de> | ||
| 2 | |||
| 3 | * eshell/em-unix.el (eshell/su, eshell/sudo): New defuns, | ||
| 4 | providing a Tramp related implementation of "su" and "sudo". | ||
| 5 | (eshell-unix-initialize): Add "su" and "sudo". | ||
| 6 | |||
| 1 | 2009-11-27 Daiki Ueno <ueno@unixuser.org> | 7 | 2009-11-27 Daiki Ueno <ueno@unixuser.org> |
| 2 | 8 | ||
| 3 | * net/socks.el (socks-send-command): Convert binary request to | 9 | * net/socks.el (socks-send-command): Convert binary request to |
diff --git a/lisp/eshell/em-unix.el b/lisp/eshell/em-unix.el index d6ba970b6bb..ceba51ea830 100644 --- a/lisp/eshell/em-unix.el +++ b/lisp/eshell/em-unix.el | |||
| @@ -145,7 +145,7 @@ Otherwise, Emacs will attempt to use rsh to invoke du on the remote machine." | |||
| 145 | (make-local-variable 'eshell-complex-commands) | 145 | (make-local-variable 'eshell-complex-commands) |
| 146 | (setq eshell-complex-commands | 146 | (setq eshell-complex-commands |
| 147 | (append '("grep" "egrep" "fgrep" "agrep" "glimpse" "locate" | 147 | (append '("grep" "egrep" "fgrep" "agrep" "glimpse" "locate" |
| 148 | "cat" "time" "cp" "mv" "make" "du" "diff") | 148 | "cat" "time" "cp" "mv" "make" "du" "diff" "su" "sudo") |
| 149 | eshell-complex-commands))) | 149 | eshell-complex-commands))) |
| 150 | 150 | ||
| 151 | (defalias 'eshell/date 'current-time-string) | 151 | (defalias 'eshell/date 'current-time-string) |
| @@ -1041,6 +1041,66 @@ Show wall-clock time elapsed during execution of COMMAND.") | |||
| 1041 | 1041 | ||
| 1042 | (put 'eshell/occur 'eshell-no-numeric-conversions t) | 1042 | (put 'eshell/occur 'eshell-no-numeric-conversions t) |
| 1043 | 1043 | ||
| 1044 | ;; Pacify the byte-compiler. | ||
| 1045 | (defvar tramp-default-proxies-alist) | ||
| 1046 | |||
| 1047 | (defun eshell/su (&rest args) | ||
| 1048 | "Alias \"su\" to call Tramp." | ||
| 1049 | (let ((-login (member "-" args)) ;; not handled by `eshell-eval-using-options' | ||
| 1050 | login) | ||
| 1051 | (eshell-eval-using-options | ||
| 1052 | "sudo" args | ||
| 1053 | '((?h "help" nil nil "show this usage screen") | ||
| 1054 | (?l "login" nil login "provide a login environment") | ||
| 1055 | (? nil nil login "provide a login environment") | ||
| 1056 | :usage "[- | -l | --login] [USER] | ||
| 1057 | Become another USER during a login session.") | ||
| 1058 | (throw 'eshell-replace-command | ||
| 1059 | (let ((user "root") | ||
| 1060 | (host (or (file-remote-p default-directory 'host) | ||
| 1061 | "localhost")) | ||
| 1062 | (dir (or (file-remote-p default-directory 'localname) | ||
| 1063 | default-directory))) | ||
| 1064 | (if (or login -login) (setq dir "~/")) | ||
| 1065 | (if (stringp (car args)) (setq user (car args))) | ||
| 1066 | (if (and (file-remote-p default-directory) | ||
| 1067 | (not (string-equal | ||
| 1068 | user (file-remote-p default-directory 'user)))) | ||
| 1069 | (add-to-list | ||
| 1070 | 'tramp-default-proxies-alist | ||
| 1071 | (list host user (file-remote-p default-directory)))) | ||
| 1072 | (eshell-parse-command | ||
| 1073 | "eshell/cd" (list (format "/su:%s@%s:%s" user host dir)))))))) | ||
| 1074 | |||
| 1075 | (put 'eshell/su 'eshell-no-numeric-conversions t) | ||
| 1076 | |||
| 1077 | (defun eshell/sudo (&rest args) | ||
| 1078 | "Alias \"sudo\" to call Tramp." | ||
| 1079 | (let (user) | ||
| 1080 | (eshell-eval-using-options | ||
| 1081 | "sudo" args | ||
| 1082 | '((?h "help" nil nil "show this usage screen") | ||
| 1083 | (?u "user" t user "execute a command as another USER") | ||
| 1084 | :show-usage | ||
| 1085 | :usage "[(-u | --user) USER] COMMAND | ||
| 1086 | Execute a COMMAND as the superuser or another USER.") | ||
| 1087 | (throw 'eshell-external | ||
| 1088 | (let* ((user (or user "root")) | ||
| 1089 | (host (or (file-remote-p default-directory 'host) | ||
| 1090 | "localhost")) | ||
| 1091 | (dir (or (file-remote-p default-directory 'localname) | ||
| 1092 | default-directory)) | ||
| 1093 | (default-directory (format "/sudo:%s@%s:%s" user host dir))) | ||
| 1094 | (if (and (file-remote-p default-directory) | ||
| 1095 | (not (string-equal | ||
| 1096 | user (file-remote-p default-directory 'user)))) | ||
| 1097 | (add-to-list | ||
| 1098 | 'tramp-default-proxies-alist | ||
| 1099 | (list host user (file-remote-p default-directory)))) | ||
| 1100 | (eshell-named-command (car args) (cdr args))))))) | ||
| 1101 | |||
| 1102 | (put 'eshell/sudo 'eshell-no-numeric-conversions t) | ||
| 1103 | |||
| 1044 | (provide 'em-unix) | 1104 | (provide 'em-unix) |
| 1045 | 1105 | ||
| 1046 | ;; Local Variables: | 1106 | ;; Local Variables: |