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

Escaping spaces broken; mysterious missing directory; data loss #1843

Closed
OJFord opened this issue Oct 13, 2016 · 7 comments
Closed

Escaping spaces broken; mysterious missing directory; data loss #1843

OJFord opened this issue Oct 13, 2016 · 7 comments

Comments

@OJFord
Copy link
Contributor

OJFord commented Oct 13, 2016

It seems that spaces cannot be escaped:

$ cd foo\ bar
cd takes 0 or 1 arguments, not 2

This somehow allowed me to create a directory, move something into it, and now not have that directory accessible at all?!

~$ mkdir Documents/foo\ bar
~$ mv thing Documents/foo\ bar
~$ cd ~/Documents/foo\ bar
cd takes 0 or 1 arguments, not 2
~$ cd '~/Documents/foo bar'
cd: no such file or directory: Documents/foo bar
~$ cd ~/Documents/foo
cd: no such file or directory: Documents/foo

The escaping issue is annoying; potentially harmful. But I can't even figure out what mkdir or mv did with the arguments they did receive?

Brought it on myself by using spaces in a way - I was just trying to be consistent with existing directories, but this definitely shouldn't fail as hard as this.

Fortunately my only data loss was a git repo without unpushed changes.

@gforsyth
Copy link
Collaborator

Hey @OJFord, thanks for reporting. See #1432 for a long discussion of this issue.
We use quotes to escape things, as \ is the Python line continuation character and Python always wins in xonsh.

As for what happened, you created two directories, one called Documents/foo\ and one called bar. You then moved thing and Documents/foo\ into bar

@OJFord
Copy link
Contributor Author

OJFord commented Oct 13, 2016

From __xonsh_history__ I can see that the \ was escaped itself:

$ __xonsh_history__[idx]
'cd ~/Documents\foo\\ bar'

@OJFord
Copy link
Contributor Author

OJFord commented Oct 13, 2016

Oops, thanks @gforsyth, sorry I missed the duplicate.

As for what happened, you created two directories, one called Documents/foo\ and one called bar. You then moved thing and Documents/foo\ into bar

That's not what happened though - none of those exist anywhere (I've checked find).

@gforsyth
Copy link
Collaborator

Not sure, then, since that's the behavior I see:

il@bad_cat ~/tmp 🐚  mkdir Documents
gil@bad_cat ~/tmp 🐚  mkdir Documents/foo\ bar
gil@bad_cat ~/tmp 🐚  touch thing
gil@bad_cat ~/tmp 🐚  mv thing Documents/foo\ bar
gil@bad_cat ~/tmp 🐚  ls
Documents  bar
gil@bad_cat ~/tmp 🐚  ls bar/
'foo\'  thing
gil@bad_cat ~/tmp 🐚  

@OJFord
Copy link
Contributor Author

OJFord commented Oct 13, 2016

Oh, sorry, no I found it.. I overspecified previously.

My actual case was more confusing since I had 5 escape characters; so it did what you described just with more things. Thanks!

I think I know where I come down on "to quote or not to quote" though... I can't imagine ever wanting a literal backslash in this way; quite often if I start typing I'll escape instead of go back to quote - though of course the tab completion helps, just not in the mkdir/mv-to-new case.

Thanks again for such quick help! 😁

@OJFord OJFord closed this as completed Oct 13, 2016
@gforsyth
Copy link
Collaborator

Happy to help! And agreed, the literal backslash is hardly ever what anyone wants.

@scopatz
Copy link
Member

scopatz commented Oct 14, 2016

As a quick though, maybe we could have an escape xontrib (as part of bashisms?) that has a precommand hook that let's people use their muscle memory? This would only affect the shalle and not scripts / the language, like other potential bashisms. It might be a good middle ground.

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

No branches or pull requests

3 participants