mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 16:45:33 +02:00
ls, rm, cp, open, touch, mkdir: Don't expand tilde if input path is quoted string or a variable. (#12232)
# 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
This commit is contained in:
2
crates/nu-command/src/env/load_env.rs
vendored
2
crates/nu-command/src/env/load_env.rs
vendored
@ -70,7 +70,7 @@ impl Command for LoadEnv {
|
||||
if env_var == "PWD" {
|
||||
let cwd = current_dir(engine_state, stack)?;
|
||||
let rhs = rhs.coerce_into_string()?;
|
||||
let rhs = nu_path::expand_path_with(rhs, cwd);
|
||||
let rhs = nu_path::expand_path_with(rhs, cwd, true);
|
||||
stack.add_env_var(
|
||||
env_var,
|
||||
Value::string(rhs.to_string_lossy(), call.head),
|
||||
|
Reference in New Issue
Block a user