Follow

So... something that's been bothering me about *nix shells recently is the need to escape spaces in filepaths and similar stuff

Is there another, good solution to it that doesn't involve things looking really ugly (and doesn't require me to manually quote things)?

I'd much prefer if I could write
"cp -r Downloads/Dir With Spaces Documents/"
instead of
"cp -r Downloads/Dir\ With\ Spaces Documents/" or similar.

· · Web · 6 · 0 · 0

@jbauer@merveilles.town I usually use manual quotes like: cp -r "Downloads/Dir With Spaces Documents/"

Is there a scenario where you can't use that? As it's only two extra symbols, and the path doesn't look ugly.

@foxhkron It's not so much that there are scenarios that I can't use that, it's more that I'd rather just not have to worry about the need to do it in the first place.

The end goal would be to make the system as "user-friendly" as possible in so much as the user interacting with the shell doesn't have to think about such simple shell-specific details as this, and can just type what they mean without worrying.

@jbauer To do so would introduce ambiguity in your prompt. If you say:
`cp -r Downloads/Dir With Spaces Documents/`
How could the shell know not to copy `Downloads/Dir`, `./With`, and `./Spaces` to `Documents/`? Space is pretty strictly a delimiter without being escaped, and workarounds would probably require complicated aliases that would be overengineered to work against the shell's parsing and would also take away functionality from tools that take an arbitrary number of arguments like `cp`.

@eonn I'm not looking to add a layer on top of an existing shell, I'm looking for a different way that might still look good, or a different strategy for delimiting arguments that doesn't involve special characters or the need for frequent escaping.

If the shell itself is built to treat spaces as spaces instead of as a delimiter, then that ambiguity wouldn't exist and programs like cp would still work fine (because it's the shell's responsibility to split and pass the args to the program)

@eonn Perhaps this is too ingrained in *nix environments to be realistically done on something like Linux or *BSD though, so it might require a whole different OS/paradigm to make it work right.

@jbauer Perhaps this could work intuitively syntactically if different keywords were used to indicate options? Like: `cp WITH recursive, force ON ./Path to place with spaces, Other space/, Other/, Space/, Destination/`. However this just makes the parsing function of spaces move to a different character that would inherit the same problem. The benefits still get turned into a exercise in yak shaving when you're making a system that allows for this in a *nix environment, so I agree.

@jbauer I think it could be done if you had some advanced parser try to guess what you wanted and check the filesystem to verify and then automatically escape for you before passing to the program

It's gonna be expensive in stat syscalls for some things I bet

@jbauer if your commands are text and involve structure you’ll always have some kind of delimiter and some need to escape it.

You could use a non-text shell of some kind, or a rarer delimiter, or… idk

@jbauer you could try to use heuristics but those can fail spectacularly and are often exploitable

@jbauer the solution is to move beyond text entry as we know it, and into a kind of prompt that is type aware. it would see that your cursor is in a position that expects a file path and switches text entry mode to file path entry mode automatically. this would include potentially an autocomplete gui that would list available files and directories as you type- and when a full qualified path entry is completed the path is displayed offset from the rest of the commands

@zens Yup, I figured it would have to be a solution along those lines.

I gotta figure out how to do GUI programming...

@zens @jbauer @csepp I switched to the Nu shell today for mostly this reason, but I think the problem is more fundamental than that and has to do with the fact that shells still emulate teletype prompts with the extras. The most interesting experiment I’ve seen to go beyond this is the Pipeworld/Arcan system but that seems nowhere near out of beta: https://arcan-fe.com/

@amanda @jbauer @zens There are also Lisp based shells. Ambrevar used to have a great blog post about it but has since deleted their blog. :sadlinux:
I'd like to replicate their setup someday.

@jbauer Unfortunately the space in the commandline is the same space they (foolishly) allowed in filenames. I usually put underscores in my filenames instead.

Sign in to participate in the conversation
Merveilles

Revel in the marvels of the universe. We are a collective of forward-thinking individuals who strive to better ourselves and our surroundings through constant creation. We express ourselves through music, art, games, and writing. We also put great value in play. A warm welcome to any like-minded people who feel these ideals resonate with them.