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

Remove cd w/ abbreviations #10588

Merged
merged 2 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 0 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion crates/nu-command/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ open = "5.0"
os_pipe = "1.1"
pathdiff = "0.2"
percent-encoding = "2.3"
powierza-coefficient = "1.0"
print-positions = "0.6"
quick-xml = "0.30"
rand = "0.8"
Expand Down
63 changes: 9 additions & 54 deletions crates/nu-command/src/filesystem/cd.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::filesystem::cd_query::query;
#[cfg(unix)]
use libc::gid_t;
use nu_engine::{current_dir, CallExt};
Expand Down Expand Up @@ -62,8 +61,6 @@ impl Command for Cd {
) -> Result<PipelineData, ShellError> {
let path_val: Option<Spanned<String>> = call.opt(engine_state, stack, 0)?;
let cwd = current_dir(engine_state, stack)?;
let config = engine_state.get_config();
let use_abbrev = config.cd_with_abbreviations;

let path_val = {
if let Some(path) = path_val {
Expand All @@ -86,22 +83,10 @@ impl Command for Cd {
let path = match nu_path::canonicalize_with(path.clone(), &cwd) {
Ok(p) => p,
Err(_) => {
if use_abbrev {
match query(&path, None, v.span) {
Ok(p) => p,
Err(_) => {
return Err(ShellError::DirectoryNotFound(
v.span,
path.to_string_lossy().to_string(),
))
}
}
} else {
return Err(ShellError::DirectoryNotFound(
v.span,
path.to_string_lossy().to_string(),
));
}
return Err(ShellError::DirectoryNotFound(
v.span,
path.to_string_lossy().to_string(),
));
}
};
(path.to_string_lossy().to_string(), v.span)
Expand All @@ -115,42 +100,17 @@ impl Command for Cd {
let path = match nu_path::canonicalize_with(path_no_whitespace, &cwd) {
Ok(p) => {
if !p.is_dir() {
if use_abbrev {
// if it's not a dir, let's check to see if it's something abbreviated
match query(&p, None, v.span) {
Ok(path) => path,
Err(_) => {
return Err(ShellError::DirectoryNotFound(
v.span,
p.to_string_lossy().to_string(),
))
}
};
} else {
return Err(ShellError::NotADirectory(v.span));
}
return Err(ShellError::NotADirectory(v.span));
};
p
}

// if canonicalize failed, let's check to see if it's abbreviated
Err(_) => {
if use_abbrev {
match query(&path_no_whitespace, None, v.span) {
Ok(path) => path,
Err(_) => {
return Err(ShellError::DirectoryNotFound(
v.span,
path_no_whitespace.to_string(),
))
}
}
} else {
return Err(ShellError::DirectoryNotFound(
v.span,
path_no_whitespace.to_string(),
));
}
return Err(ShellError::DirectoryNotFound(
v.span,
path_no_whitespace.to_string(),
));
}
};
(path.to_string_lossy().to_string(), v.span)
Expand Down Expand Up @@ -188,11 +148,6 @@ impl Command for Cd {
example: r#"cd ~"#,
result: None,
},
Example {
description: "Change to a directory via abbreviations",
example: r#"cd d/s/9"#,
result: None,
},
Example {
description: "Change to the previous working directory ($OLDPWD)",
example: r#"cd -"#,
Expand Down