Skip to content

ls, rm, cp, open, touch, mkdir: Don't expand tilde if input path is quoted string or a variable. - #12232

Merged
WindSoilder merged 12 commits into
nushell:mainfrom
WindSoilder:no_tilde
Mar 25, 2024
Merged

WindSoilder merged 12 commits into
nushell:mainfrom
WindSoilder:no_tilde

Conversation

@WindSoilder

@WindSoilder WindSoilder commented Mar 19, 2024 •

Copy link
Copy Markdown
Contributor

Description

Fixes: #11887
Fixes: #11626

This pr unify the tilde expand behavior over several filesystem relative commands. It follows the same rule with glob expansion:

command result
ls ~/aaa expand tilde
ls "~/aaa" don't expand tilde
let f = "~/aaa"; ls $f don't expand tilde, if you want to: use ls ($f | path expand)
let f: glob = "~/aaa"; ls $f expand tilde, they don't expand on mkdir, touch comamnd.

Actually I'm not sure for 4th item, currently it's expanding is just because it followes the same rule with glob expansion.

About the change

It changes expand_path_with to accept a new argument called expand_tilde, if it's true, expand it, if not, just keep it as ~ itself.

User-Facing Changes

After this change, ls "~/aaa" won't expand tilde.

Tests + Formatting

Done

@WindSoilder
WindSoilder marked this pull request as draft March 19, 2024 22:53
@WindSoilder WindSoilder changed the title ls, rm, cp, open: Don't expand tilde if input path is quoted string or a variable. ls, rm, cp, open, touch, mkdir: Don't expand tilde if input path is quoted string or a variable. Mar 19, 2024
@WindSoilder
WindSoilder marked this pull request as ready for review March 20, 2024 00:10
@WindSoilder WindSoilder added notes:breaking-changes Noted in Breaking Changes section notes:fixes Noted in "Bug fixes" section labels Mar 20, 2024
@kubouch

kubouch commented Mar 21, 2024 •

Copy link
Copy Markdown
Contributor

It seems good to me. One slightly weird thing about it is that ~ is now considered a "glob": let f: glob = "~/aaa"; ls $f. But I'm OK with it for consistency. The mkdir and touch not expanding makes sense because they don't accept a glob type. You can do touch ($f | into string | path expand) -- less ideal, but doable.

I'd be fine merging it, but maybe someone else could look at it as well.

@WindSoilder
WindSoilder merged commit 87c5f6e into nushell:main Mar 25, 2024
@WindSoilder

Copy link
Copy Markdown
Contributor Author

Then let's merge it and see how it works :)

@hustcer hustcer added this to the v0.92.0 milestone Mar 25, 2024
@crabdancing

crabdancing commented Mar 26, 2024 •

Copy link
Copy Markdown

I know my issue is partially to blame for this, but I'd say this doesn't cover all use cases. :P

It should be possible to get path expansion while still having spaces in the path. Ideally we would have one quote type for that, and another quote type with the new behavior. E.g., maybe backtick (`), unless we're planning something else with that. Or we could adopt the Bash behavior and use the " vs ' distinction, though I wouldn't blame people for not liking it from an intuitive standpoint.

@WindSoilder

Copy link
Copy Markdown
Contributor Author

Thanks for your feedback!
I think currently backtick will expand home path, isn't it? These two are different:

ls `~/aa bb`
ls "~/aa bb"

@crabdancing

Copy link
Copy Markdown

Oh :S

You're totally, completely right. I think a backtick placement issue from my path tab completion must have confused me or something. Thank you for the response!

By the way, do you have any answer to a good implementation of tab completion to file paths with spaces? There have been a lot of changes in Nushell, and my code is barely functional at this point! :P

@WindSoilder

Copy link
Copy Markdown
Contributor Author

By the way, do you have any answer to a good implementation of tab completion to file paths with spaces?

Sorry I don't, I don't touch much of tab completion of nushell, but I think it needs to be changed to fit new rules.

@crabdancing

Copy link
Copy Markdown

No worries :)

@adrian5

adrian5 commented Apr 13, 2024

Copy link
Copy Markdown

Thanks for your feedback! I think currently backtick will expand home path, isn't it? These two are different:

ls `~/aa bb`
ls "~/aa bb"

Should the backtick difference be mentioned in working with strings?

@WindSoilder

Copy link
Copy Markdown
Contributor Author

They should be different, I think the documentation is outdated.

Currently backtick is simply a bare word, but it allows to have spaces. So:

`abc`

and

abc

are the same thing, but have some difference to "abc" and 'abc'

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

Labels

notes:breaking-changes Noted in Breaking Changes section notes:fixes Noted in "Bug fixes" section

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Behavior of ~ is inconsistent with user expectation Inconsistent path expansions between ls, cp, mv, rm, and mkdir

5 participants