Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for backslash space escape #3595

Closed
jonathanhogg opened this issue May 28, 2020 · 6 comments
Closed

Support for backslash space escape #3595

jonathanhogg opened this issue May 28, 2020 · 6 comments

Comments

@jonathanhogg
Copy link
Contributor

xonfig

+------------------+---------------------+
| xonsh            | 0.9.18              |
| Git SHA          | 26475146            |
| Commit Date      | May 5 06:42:28 2020 |
| Python           | 3.8.2               |
| PLY              | 3.11                |
| have readline    | True                |
| prompt toolkit   | 3.0.5               |
| shell type       | prompt_toolkit      |
| pygments         | 2.6.1               |
| on posix         | True                |
| on linux         | False               |
| on darwin        | True                |
| on windows       | False               |
| on cygwin        | False               |
| on msys2         | False               |
| is superuser     | False               |
| default encoding | utf-8               |
| xonsh encoding   | utf-8               |
| encoding errors  | surrogateescape     |
+------------------+---------------------+

Expected Behavior

It would be incredibly useful (to me, at least) if xonsh supported the standard shell backslash space escape on the command line.

While one can work around this by quoting the filename, the specific pain is that dragging a file into a terminal on macOS will helpfully paste the filename into it. Unfortunately, it assumes a regular shell and so uses backslash space escapes when it does this. Since using spaces in filenames is incredibly common in a primarily GUI-driven OS like macOS, that causes significant grief as it means editing the command line after dragging the file in.

Current Behavior

A command line using the backslash space escape won't work in xonsh – the spaces are interpreted as separators and the backslashes as literal backslashes.

Steps to Reproduce

Basically any command line with an escaped space, e.g.:

frank$ touch 'a b'                                                                                                      
frank$ ls a\ b                                                                                                          
ls: a\: No such file or directory
ls: b: No such file or directory
@laloch
Copy link
Member

laloch commented Jun 24, 2020

Hi @jonathanhogg, thanks for the suggestion and sorry for the delay.
I'm afraid, that the requested backslash escapes are not going to happen. Xonsh's way of escaping special characters simply is quoting.
I also strongly feel that your terminal emulator does not do the right thing(TM) and that you should file a bug report there.

@jonathanhogg
Copy link
Contributor Author

Thanks. Yes, I am aware how to quote in xonsh – I have been a user for quite some time now :-)

I raised the issue because one of @scopatz 's original key user bases for xonsh was mean to be scientists and a large number of scientists use macOS. A side benefit is, of course, familiarity for people moving from other command-line shells that do support backslash escapes.

While I agree that Terminal.app here is probably making a poor assumption about the underlying shell, it is also the default terminal app on macOS. Historically, changing the direction of Apple has proven to be harder than open source projects. It was a suggestion that you are, of course, welcome to ignore ;-)

@laloch
Copy link
Member

laloch commented Jun 25, 2020

This has been settled a long time ago. See, for instance, #1432.

While I agree that Terminal.app here is probably making a poor assumption about the underlying shell, it is also the default terminal app on macOS.

It does not only make poor assumptions, but it also chooses the worst implementation possible based on those assumptions. Even for bash and zsh (and other sh-like shells) the correct solution would be to quote the file name using single quotation marks to prevent accidental expansion of special characters.
The most correct would, of course, be to make the behavior configurable, but I realize that's a no-go in the Apple ecosystem.

@laloch
Copy link
Member

laloch commented Jun 25, 2020

Oh, and I completely forgot to mention Subprocess Strings tutorial providing some discussion and explanation.

@jonathanhogg
Copy link
Contributor Author

Fair enough, I didn't mean to dig up an old can of worms. I was just trying to point out a valid use case for a class of users for which xonsh has a regression vs other shells.

The great thing about open source is there's room to fork.

@bestlem
Copy link
Contributor

bestlem commented Dec 1, 2020

Just as a note for others who might find the same issue I had. It is not a bug in xonsh but a feature in emacs.

It is not just macOS but on non Microsoft Systems emacs call to sanitise shell arguments shell-quote-argument uses \ escaping to deal with spaces - note that it also escapes other non posix filename characters so makes sense for that consistency, but with unicode filenames that is broken in emacs. So no need to change xonsh.

Emacs code for reference is

;; Quote everything except POSIX filename characters.
;; This should be safe enough even for really weird shells.

(replace-regexp-in-string
"\n" "'\n'"
(replace-regexp-in-string "[^-0-9a-zA-Z_./\n]" "\\\&" argument))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants