Commit e7b538cd authored by Michael Albinus's avatar Michael Albinus
Browse files

* eshell/em-unix (eshell/whoami): Make it a defun but a defalias.

(eshell/su): Flatten args.  Apply better args parsing.  Use "cd".
(eshell/sudo): Flatten args.  Let-bind `default-directory'.
parent e2a421af
...@@ -955,7 +955,9 @@ Show wall-clock time elapsed during execution of COMMAND.") ...@@ -955,7 +955,9 @@ Show wall-clock time elapsed during execution of COMMAND.")
(eshell-stringify-list (eshell-stringify-list
(eshell-flatten-list (cdr time-args)))))))) (eshell-flatten-list (cdr time-args))))))))
(defalias 'eshell/whoami 'user-login-name) (defun eshell/whoami (&rest args)
"Make \"whoami\" Tramp aware."
(or (file-remote-p default-directory 'user) (user-login-name)))
(defvar eshell-diff-window-config nil) (defvar eshell-diff-window-config nil)
...@@ -1046,8 +1048,8 @@ Show wall-clock time elapsed during execution of COMMAND.") ...@@ -1046,8 +1048,8 @@ Show wall-clock time elapsed during execution of COMMAND.")
(defun eshell/su (&rest args) (defun eshell/su (&rest args)
"Alias \"su\" to call Tramp." "Alias \"su\" to call Tramp."
(let ((-login (member "-" args)) ;; not handled by `eshell-eval-using-options' (setq args (eshell-stringify-list (eshell-flatten-list args)))
login) (let (login)
(eshell-eval-using-options (eshell-eval-using-options
"sudo" args "sudo" args
'((?h "help" nil nil "show this usage screen") '((?h "help" nil nil "show this usage screen")
...@@ -1061,8 +1063,9 @@ Become another USER during a login session.") ...@@ -1061,8 +1063,9 @@ Become another USER during a login session.")
"localhost")) "localhost"))
(dir (or (file-remote-p default-directory 'localname) (dir (or (file-remote-p default-directory 'localname)
default-directory))) default-directory)))
(if (or login -login) (setq dir "~/")) (eshell-for arg args
(if (stringp (car args)) (setq user (car args))) (if (string-equal arg "-") (setq login t) (setq user arg)))
(if login (setq dir "~/"))
(if (and (file-remote-p default-directory) (if (and (file-remote-p default-directory)
(not (string-equal (not (string-equal
user (file-remote-p default-directory 'user)))) user (file-remote-p default-directory 'user))))
...@@ -1070,12 +1073,13 @@ Become another USER during a login session.") ...@@ -1070,12 +1073,13 @@ Become another USER during a login session.")
'tramp-default-proxies-alist 'tramp-default-proxies-alist
(list host user (file-remote-p default-directory)))) (list host user (file-remote-p default-directory))))
(eshell-parse-command (eshell-parse-command
"eshell/cd" (list (format "/su:%s@%s:%s" user host dir)))))))) "cd" (list (format "/su:%s@%s:%s" user host dir))))))))
(put 'eshell/su 'eshell-no-numeric-conversions t) (put 'eshell/su 'eshell-no-numeric-conversions t)
(defun eshell/sudo (&rest args) (defun eshell/sudo (&rest args)
"Alias \"sudo\" to call Tramp." "Alias \"sudo\" to call Tramp."
(setq args (eshell-stringify-list (eshell-flatten-list args)))
(let (user) (let (user)
(eshell-eval-using-options (eshell-eval-using-options
"sudo" args "sudo" args
...@@ -1089,15 +1093,15 @@ Execute a COMMAND as the superuser or another USER.") ...@@ -1089,15 +1093,15 @@ Execute a COMMAND as the superuser or another USER.")
(host (or (file-remote-p default-directory 'host) (host (or (file-remote-p default-directory 'host)
"localhost")) "localhost"))
(dir (or (file-remote-p default-directory 'localname) (dir (or (file-remote-p default-directory 'localname)
default-directory)) default-directory)))
(default-directory (format "/sudo:%s@%s:%s" user host dir)))
(if (and (file-remote-p default-directory) (if (and (file-remote-p default-directory)
(not (string-equal (not (string-equal
user (file-remote-p default-directory 'user)))) user (file-remote-p default-directory 'user))))
(add-to-list (add-to-list
'tramp-default-proxies-alist 'tramp-default-proxies-alist
(list host user (file-remote-p default-directory)))) (list host user (file-remote-p default-directory))))
(eshell-named-command (car args) (cdr args))))))) (let ((default-directory (format "/sudo:%s@%s:%s" user host dir)))
(eshell-named-command (car args) (cdr args))))))))
(put 'eshell/sudo 'eshell-no-numeric-conversions t) (put 'eshell/sudo 'eshell-no-numeric-conversions t)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment