(autoload 'eshell-parse-command "esh-cmd")
-(defun eshell/su (&rest arguments)
+(defun eshell/su (&rest args)
"Alias \"su\" to call TRAMP.
Uses the system su through TRAMP's su method."
- (setq arguments (eshell-stringify-list (flatten-tree arguments)))
(eshell-eval-using-options
- "su" arguments
+ "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")
(prefix (file-remote-p default-directory)))
(dolist (arg args)
(if (string-equal arg "-") (setq login t) (setq user arg)))
- ;; `eshell-eval-using-options' tries to handle "-" as a
- ;; short option; double-check whether the original
- ;; arguments include it.
- (when (member "-" arguments) (setq login t))
(when login (setq dir "~/"))
(if (and prefix
(or
(memq :parse-leading-options-only options))))
(setq arg (nth ai eshell--args))
(if (not (and (stringp arg)
+ ;; A string of length 1 can't be an option; (if
+ ;; it's "-", that generally means stdin).
+ (> (length arg) 1)
(string-match "^-\\(-\\)?\\(.*\\)" arg)))
;; Positional argument found, skip
(setq ai (1+ ai)
(if (> (length switch) 0)
(eshell--process-option name switch 1 ai options opt-vals)
(setq ai (length eshell--args)))
- (while (> (length switch) 0)
- (setq switch (eshell--process-option name switch 0
- ai options opt-vals)))))))
+ (while (> (length switch) 0)
+ (setq switch (eshell--process-option name switch 0
+ ai options opt-vals)))))))
(nconc (mapcar #'cdr opt-vals) eshell--args)))
(provide 'esh-opt)
(should (equal ignore-pattern "*.txt"))
(should (equal args '("/some/path")))))
+(ert-deftest esh-opt-test/eval-using-options-stdin ()
+ "Test that \"-\" is a positional arg in `eshell-eval-using-options'."
+ (eshell-eval-using-options
+ "cat" '("-")
+ '((?A "show-all" nil show-all
+ "show all characters"))
+ (should (eq show-all nil))
+ (should (equal args '("-"))))
+ (eshell-eval-using-options
+ "cat" '("-A" "-")
+ '((?A "show-all" nil show-all
+ "show all characters"))
+ (should (eq show-all t))
+ (should (equal args '("-"))))
+ (eshell-eval-using-options
+ "cat" '("-" "-A")
+ '((?A "show-all" nil show-all
+ "show all characters"))
+ (should (eq show-all t))
+ (should (equal args '("-")))))
+
(ert-deftest esh-opt-test/eval-using-options-terminate-options ()
"Test that \"--\" terminates options in `eshell-eval-using-options'."
(eshell-eval-using-options