(defun eshell-parse-user-reference ()
"An argument beginning with ~ is a filename to be expanded."
(when (and (not eshell-current-argument)
+ (not eshell-current-quoted)
(eq (char-after) ?~))
;; Apply this modifier fairly early so it happens before things
;; like glob expansion.
default-directory))))
;;; Tests:
+\f
+;; Variables
+
(ert-deftest em-dirs-test/pwd-var ()
"Test using the $PWD variable."
(let ((default-directory "/some/path"))
(eshell-match-command-output "echo $-[1][/ 1 3]"
"(\"some\" \"here\")\n"))))
+\f
+;; Argument expansion
+
+(ert-deftest em-dirs-test/expand-user-reference/local ()
+ "Test expansion of \"~USER\" references."
+ (eshell-command-result-equal "echo ~" (expand-file-name "~"))
+ (eshell-command-result-equal
+ (format "echo ~%s" user-login-name)
+ (expand-file-name (format "~%s" user-login-name))))
+
+(ert-deftest em-dirs-test/expand-user-reference/quoted ()
+ "Test that a quoted \"~\" isn't expanded."
+ (eshell-command-result-equal "echo \\~" "~")
+ (eshell-command-result-equal "echo \"~\"" "~")
+ (eshell-command-result-equal "echo '~'" "~"))
+
+\f
+;; `cd'
+
(ert-deftest em-dirs-test/cd ()
"Test that changing directories with `cd' works."
(ert-with-temp-directory tmpdir