unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Jonathan Kyle Mitchell <kyle@jonathanmitchell.org>
To: 30724@debbugs.gnu.org
Cc: Noam Postavsky <npostavs@gmail.com>,
	"; Yegor Timoshenko" <yegortimoshenko@riseup.net>
Subject: bug#30724: eshell: escaped tilde is not treated as such
Date: Fri, 06 Jul 2018 02:24:20 -0500	[thread overview]
Message-ID: <97031714eb3479b466bca0545b76114e4d40e898.camel@jonathanmitchell.org> (raw)
In-Reply-To: <f36b217ce91c3eab35e65ba72d16362@riseup.net>

[-- Attachment #1: Type: text/plain, Size: 2187 bytes --]

tags 30724 + patch
quit

I found a way to get eshell to escape special chars.  It seems most of
the eshell builtin commands that take file arguments are already tagged
with the eshell-no-numeric-conversions property.  By adding the true
part of the if condition in eshell-lisp-command, it is possible to
quote the arguments of special filenames.  The attached patch checks
for "~" and "*".

;; for reference, here's the set of eshell builtins with the
;; eshell-no-numeric-conversions property
./esh-proc.el\0202:(put 'eshell/kill 'eshell-no-numeric-conversions t)
./em-dirs.el\0409:(put 'eshell/cd 'eshell-no-numeric-conversions t)
./em-dirs.el\0472:(put 'eshell/pushd 'eshell-no-numeric-conversions t)
./em-dirs.el\0502:(put 'eshell/popd 'eshell-no-numeric-conversions t)
./esh-ext.el\0261:(put 'eshell/addpath 'eshell-no-numeric-conversions t
./esh-util.el\091:  (put \\='find-file \\='eshell-no-numeric-
./em-script.el\0127:(put 'eshell/source 'eshell-no-numeric-conversions
./em-script.el\0140:(put 'eshell/. 'eshell-no-numeric-conversions t)
./em-unix.el\0167:(put 'eshell/man 'eshell-no-numeric-conversions t)
./em-unix.el\0309:(put 'eshell/rm 'eshell-no-numeric-conversions t)
./em-unix.el\0326:(put 'eshell/mkdir 'eshell-no-numeric-conversions t)
./em-unix.el\0342:(put 'eshell/rmdir 'eshell-no-numeric-conversions t)
./em-unix.el\0526:(put 'eshell/mv 'eshell-no-numeric-conversions t)
./em-unix.el\0563:(put 'eshell/cp 'eshell-no-numeric-conversions t)
./em-unix.el\0595:(put 'eshell/ln 'eshell-no-numeric-conversions t)
./em-unix.el\0647:(put 'eshell/cat 'eshell-no-numeric-conversions t)
./em-unix.el\0664:(put 'eshell/make 'eshell-no-numeric-conversions t)
./em-unix.el\01031:(put 'eshell/diff 'eshell-no-numeric-conversions t)
./em-unix.el\01050:(put 'eshell/locate 'eshell-no-numeric-conversions 
./em-unix.el\01059:(put 'eshell/occur 'eshell-no-numeric-conversions t)
./esh-cmd.el\01185:(put 'eshell/which 'eshell-no-numeric-conversions t)
./em-ls.el\0336:(put 'eshell/ls 'eshell-no-numeric-conversions t)
./em-tramp.el\097:(put 'eshell/su 'eshell-no-numeric-conversions t)
./em-tramp.el\0139:(put 'eshell/sudo 'eshell-no-numeric-conversions t)

--
Jonathan Kyle Mitchell

[-- Attachment #2: 0001-Check-for-filenames-special-to-the-shell-before-runn.patch --]
[-- Type: text/x-patch, Size: 1871 bytes --]

From 1aad963a71fca1abfff6d4522ddf83a07391712a Mon Sep 17 00:00:00 2001
From: Jonathan Kyle Mitchell <kyle@jonathanmitchell.org>
Date: Fri, 6 Jul 2018 01:40:32 -0500
Subject: [PATCH] Check for filenames special to the shell before running a
 command

Fix bug#30724 by checking if "*" and "~" are arguments to the current command
and quoting them relative to `default-directory' if so.  This leverages the
the fact that the existing eshell builtin commands that accept file arguments
are tagged with the eshell-no-numeric-conversions property.  The existing
details of eshell command execution are left unchanged.

* lisp/eshell/esh-cmd.el (eshell-lisp-command)
---
 lisp/eshell/esh-cmd.el | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/lisp/eshell/esh-cmd.el b/lisp/eshell/esh-cmd.el
index 61c0ebc71d..a22309a85e 100644
--- a/lisp/eshell/esh-cmd.el
+++ b/lisp/eshell/esh-cmd.el
@@ -1310,9 +1310,20 @@ eshell-lisp-command
 		  (setq eshell-last-arguments args
 			eshell-last-command-name
 			(concat "#<function " (symbol-name object) ">"))
-		  ;; if any of the arguments are flagged as numbers
-		  ;; waiting for conversion, convert them now
-		  (unless (get object 'eshell-no-numeric-conversions)
+		  (if (get object 'eshell-no-numeric-conversions)
+		      ;; check for filenames special to the shell and
+		      ;; quote them relative to `default-directory'
+		      (while args
+			(let ((arg (car args)))
+			  (if (and (stringp arg)
+				   (member arg '("~" "*")))
+			      (setcar args (concat (file-name-quote
+						    (expand-file-name
+						     default-directory))
+						   arg))))
+			(setq args (cdr args)))
+		    ;; if any of the arguments are flagged as numbers
+		    ;; waiting for conversion, convert them now
 		    (while args
 		      (let ((arg (car args)))
 			(if (and (stringp arg)
-- 
2.17.1


  parent reply	other threads:[~2018-07-06  7:24 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-06  4:30 bug#30724: eshell: escaped tilde is not treated as such Yegor Timoshenko
2018-03-09  1:15 ` Noam Postavsky
2018-07-06  7:24 ` Jonathan Kyle Mitchell [this message]
2018-07-07 19:17   ` Noam Postavsky
2018-07-15 17:18     ` Jonathan Kyle Mitchell
2018-07-17  0:14       ` Noam Postavsky
2018-07-18  3:54         ` Jonathan Kyle Mitchell
2018-07-22  1:34           ` Noam Postavsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=97031714eb3479b466bca0545b76114e4d40e898.camel@jonathanmitchell.org \
    --to=kyle@jonathanmitchell.org \
    --cc=30724@debbugs.gnu.org \
    --cc=npostavs@gmail.com \
    --cc=yegortimoshenko@riseup.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).