Commit 5de44411 authored by Jonathan Kyle Mitchell's avatar Jonathan Kyle Mitchell Committed by Noam Postavsky

Check for special filenames in eshell (Bug#30724)

* lisp/eshell/esh-cmd.el (eshell-lisp-command): Check for "~"
in lisp commands with the eshell-filename-arguments property
(Bug#30724).

* lisp/eshell/em-dirs.el (eshell/cd, eshell/pushd, eshell/popd):
* lisp/eshell/em-ls.el (eshell/ls):
* lisp/eshell/em-unix.el (eshell/rm, eshell/mkdir, eshell/rmdir)
(eshell/mv, eshell/cp, eshell/ln, eshell/cat, eshell/du, eshell/diff):
* lisp/eshell/esh-ext.el (eshell/addpath): Add
eshell-filename-arguments to symbol plist.
parent 1b4b9659
...@@ -407,6 +407,7 @@ in the minibuffer: ...@@ -407,6 +407,7 @@ in the minibuffer:
nil)))) nil))))
(put 'eshell/cd 'eshell-no-numeric-conversions t) (put 'eshell/cd 'eshell-no-numeric-conversions t)
(put 'eshell/cd 'eshell-filename-arguments t)
(defun eshell-add-to-dir-ring (path) (defun eshell-add-to-dir-ring (path)
"Add PATH to the last-dir-ring, if applicable." "Add PATH to the last-dir-ring, if applicable."
...@@ -470,6 +471,7 @@ in the minibuffer: ...@@ -470,6 +471,7 @@ in the minibuffer:
nil) nil)
(put 'eshell/pushd 'eshell-no-numeric-conversions t) (put 'eshell/pushd 'eshell-no-numeric-conversions t)
(put 'eshell/pushd 'eshell-filename-arguments t)
;;; popd [+n] ;;; popd [+n]
(defun eshell/popd (&rest args) (defun eshell/popd (&rest args)
...@@ -500,6 +502,7 @@ in the minibuffer: ...@@ -500,6 +502,7 @@ in the minibuffer:
nil) nil)
(put 'eshell/popd 'eshell-no-numeric-conversions t) (put 'eshell/popd 'eshell-no-numeric-conversions t)
(put 'eshell/pop 'eshell-filename-arguments t)
(defun eshell/dirs (&optional if-verbose) (defun eshell/dirs (&optional if-verbose)
"Implementation of dirs in Lisp." "Implementation of dirs in Lisp."
......
...@@ -334,6 +334,7 @@ instead." ...@@ -334,6 +334,7 @@ instead."
(apply 'eshell-do-ls args))) (apply 'eshell-do-ls args)))
(put 'eshell/ls 'eshell-no-numeric-conversions t) (put 'eshell/ls 'eshell-no-numeric-conversions t)
(put 'eshell/ls 'eshell-filename-arguments t)
(declare-function eshell-glob-regexp "em-glob" (pattern)) (declare-function eshell-glob-regexp "em-glob" (pattern))
......
...@@ -307,6 +307,7 @@ Remove (unlink) the FILE(s).") ...@@ -307,6 +307,7 @@ Remove (unlink) the FILE(s).")
nil)) nil))
(put 'eshell/rm 'eshell-no-numeric-conversions t) (put 'eshell/rm 'eshell-no-numeric-conversions t)
(put 'eshell/rm 'eshell-filename-arguments t)
(defun eshell/mkdir (&rest args) (defun eshell/mkdir (&rest args)
"Implementation of mkdir in Lisp." "Implementation of mkdir in Lisp."
...@@ -324,6 +325,7 @@ Create the DIRECTORY(ies), if they do not already exist.") ...@@ -324,6 +325,7 @@ Create the DIRECTORY(ies), if they do not already exist.")
nil)) nil))
(put 'eshell/mkdir 'eshell-no-numeric-conversions t) (put 'eshell/mkdir 'eshell-no-numeric-conversions t)
(put 'eshell/mkdir 'eshell-filename-arguments t)
(defun eshell/rmdir (&rest args) (defun eshell/rmdir (&rest args)
"Implementation of rmdir in Lisp." "Implementation of rmdir in Lisp."
...@@ -340,6 +342,7 @@ Remove the DIRECTORY(ies), if they are empty.") ...@@ -340,6 +342,7 @@ Remove the DIRECTORY(ies), if they are empty.")
nil)) nil))
(put 'eshell/rmdir 'eshell-no-numeric-conversions t) (put 'eshell/rmdir 'eshell-no-numeric-conversions t)
(put 'eshell/rmdir 'eshell-filename-arguments t)
(defvar no-dereference) (defvar no-dereference)
...@@ -524,6 +527,7 @@ Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY. ...@@ -524,6 +527,7 @@ Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.
eshell-mv-overwrite-files)))) eshell-mv-overwrite-files))))
(put 'eshell/mv 'eshell-no-numeric-conversions t) (put 'eshell/mv 'eshell-no-numeric-conversions t)
(put 'eshell/mv 'eshell-filename-arguments t)
(defun eshell/cp (&rest args) (defun eshell/cp (&rest args)
"Implementation of cp in Lisp." "Implementation of cp in Lisp."
...@@ -561,6 +565,7 @@ Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.") ...@@ -561,6 +565,7 @@ Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.")
eshell-cp-overwrite-files preserve))) eshell-cp-overwrite-files preserve)))
(put 'eshell/cp 'eshell-no-numeric-conversions t) (put 'eshell/cp 'eshell-no-numeric-conversions t)
(put 'eshell/cp 'eshell-filename-arguments t)
(defun eshell/ln (&rest args) (defun eshell/ln (&rest args)
"Implementation of ln in Lisp." "Implementation of ln in Lisp."
...@@ -593,6 +598,7 @@ with `--symbolic'. When creating hard links, each TARGET must exist.") ...@@ -593,6 +598,7 @@ with `--symbolic'. When creating hard links, each TARGET must exist.")
eshell-ln-overwrite-files)))) eshell-ln-overwrite-files))))
(put 'eshell/ln 'eshell-no-numeric-conversions t) (put 'eshell/ln 'eshell-no-numeric-conversions t)
(put 'eshell/ln 'eshell-filename-arguments t)
(defun eshell/cat (&rest args) (defun eshell/cat (&rest args)
"Implementation of cat in Lisp. "Implementation of cat in Lisp.
...@@ -645,6 +651,7 @@ Concatenate FILE(s), or standard input, to standard output.") ...@@ -645,6 +651,7 @@ Concatenate FILE(s), or standard input, to standard output.")
(setq eshell-ensure-newline-p nil)))) (setq eshell-ensure-newline-p nil))))
(put 'eshell/cat 'eshell-no-numeric-conversions t) (put 'eshell/cat 'eshell-no-numeric-conversions t)
(put 'eshell/cat 'eshell-filename-arguments t)
;; special front-end functions for compilation-mode buffers ;; special front-end functions for compilation-mode buffers
...@@ -927,6 +934,8 @@ Summarize disk usage of each FILE, recursively for directories.") ...@@ -927,6 +934,8 @@ Summarize disk usage of each FILE, recursively for directories.")
(eshell-print (concat (eshell-du-size-string size) (eshell-print (concat (eshell-du-size-string size)
"total\n")))))))) "total\n"))))))))
(put 'eshell/du 'eshell-filename-arguments t)
(defvar eshell-time-start nil) (defvar eshell-time-start nil)
(defun eshell-show-elapsed-time () (defun eshell-show-elapsed-time ()
...@@ -1029,6 +1038,7 @@ Show wall-clock time elapsed during execution of COMMAND.") ...@@ -1029,6 +1038,7 @@ Show wall-clock time elapsed during execution of COMMAND.")
nil) nil)
(put 'eshell/diff 'eshell-no-numeric-conversions t) (put 'eshell/diff 'eshell-no-numeric-conversions t)
(put 'eshell/diff 'eshell-filename-arguments t)
(defvar locate-history-list) (defvar locate-history-list)
......
...@@ -1304,27 +1304,36 @@ messages, and errors." ...@@ -1304,27 +1304,36 @@ messages, and errors."
"Insert Lisp OBJECT, using ARGS if a function." "Insert Lisp OBJECT, using ARGS if a function."
(catch 'eshell-external ; deferred to an external command (catch 'eshell-external ; deferred to an external command
(let* ((eshell-ensure-newline-p (eshell-interactive-output-p)) (let* ((eshell-ensure-newline-p (eshell-interactive-output-p))
(result (result
(if (functionp object) (if (functionp object)
(progn (progn
(setq eshell-last-arguments args (setq eshell-last-arguments args
eshell-last-command-name eshell-last-command-name
(concat "#<function " (symbol-name object) ">")) (concat "#<function " (symbol-name object) ">"))
;; if any of the arguments are flagged as numbers (let ((numeric (not (get object
;; waiting for conversion, convert them now 'eshell-no-numeric-conversions)))
(unless (get object 'eshell-no-numeric-conversions) (fname-args (get object 'eshell-filename-arguments)))
(while args (when (or numeric fname-args)
(let ((arg (car args))) (while args
(if (and (stringp arg) (let ((arg (car args)))
(> (length arg) 0) (cond ((and numeric (stringp arg) (> (length arg) 0)
(not (text-property-not-all (text-property-any 0 (length arg)
0 (length arg) 'number t arg))) 'number t arg))
(setcar args (string-to-number arg)))) ;; If any of the arguments are
(setq args (cdr args)))) ;; flagged as numbers waiting for
(eshell-apply object eshell-last-arguments)) ;; conversion, convert them now.
(setq eshell-last-arguments args (setcar args (string-to-number arg)))
eshell-last-command-name "#<Lisp object>") ((and fname-args (stringp arg)
(eshell-eval object)))) (string-equal arg "~"))
;; If any of the arguments match "~",
;; prepend "./" to treat it as a
;; regular file name.
(setcar args (concat "./" arg)))))
(setq args (cdr args)))))
(eshell-apply object eshell-last-arguments))
(setq eshell-last-arguments args
eshell-last-command-name "#<Lisp object>")
(eshell-eval object))))
(if (and eshell-ensure-newline-p (if (and eshell-ensure-newline-p
(save-excursion (save-excursion
(goto-char eshell-last-output-end) (goto-char eshell-last-output-end)
......
...@@ -259,6 +259,7 @@ Adds the given PATH to $PATH.") ...@@ -259,6 +259,7 @@ Adds the given PATH to $PATH.")
(eshell-printn dir))))) (eshell-printn dir)))))
(put 'eshell/addpath 'eshell-no-numeric-conversions t) (put 'eshell/addpath 'eshell-no-numeric-conversions t)
(put 'eshell/addpath 'eshell-filename-arguments t)
(defun eshell-script-interpreter (file) (defun eshell-script-interpreter (file)
"Extract the script to run from FILE, if it has #!<interp> in it. "Extract the script to run from FILE, if it has #!<interp> in it.
......
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