mirror of
https://github.com/nushell/nushell
synced 2024-12-27 05:23:11 +00:00
Better ls paths (#4612)
* Fix ls paths... again * Fix ls paths... again * Always expand paths inside of glob_from * Expand in ls before we check for directory info
This commit is contained in:
parent
f507613b38
commit
676457acd3
2 changed files with 11 additions and 14 deletions
|
@ -29,11 +29,8 @@ impl Command for Ls {
|
|||
|
||||
fn signature(&self) -> nu_protocol::Signature {
|
||||
Signature::build("ls")
|
||||
.optional(
|
||||
"pattern",
|
||||
SyntaxShape::GlobPattern,
|
||||
"the glob pattern to use",
|
||||
)
|
||||
// Using a string instead of a glob pattern shape so it won't auto-expand
|
||||
.optional("pattern", SyntaxShape::String, "the glob pattern to use")
|
||||
.switch("all", "Show hidden files", Some('a'))
|
||||
.switch(
|
||||
"long",
|
||||
|
@ -69,18 +66,22 @@ impl Command for Ls {
|
|||
let ctrl_c = engine_state.ctrlc.clone();
|
||||
let call_span = call.head;
|
||||
let cwd = current_dir(engine_state, stack)?;
|
||||
let pattern_arg = call.opt::<Spanned<String>>(engine_state, stack, 0)?;
|
||||
|
||||
let pattern_arg: Option<Spanned<String>> = call.opt(engine_state, stack, 0)?;
|
||||
|
||||
let (path, p_tag, absolute_path) = match pattern_arg {
|
||||
Some(p) => {
|
||||
let p_tag = p.span;
|
||||
let mut p = PathBuf::from(p.item);
|
||||
if p.is_dir() {
|
||||
|
||||
let expanded = nu_path::expand_path_with(&p, &cwd);
|
||||
if expanded.is_dir() {
|
||||
if permission_denied(&p) {
|
||||
#[cfg(unix)]
|
||||
let error_msg = format!(
|
||||
"The permissions of {:o} do not allow access for this user",
|
||||
p.metadata()
|
||||
expanded
|
||||
.metadata()
|
||||
.expect(
|
||||
"this shouldn't be called since we already know there is a dir"
|
||||
)
|
||||
|
@ -96,7 +97,7 @@ impl Command for Ls {
|
|||
p_tag,
|
||||
));
|
||||
}
|
||||
if is_empty_dir(&p) {
|
||||
if is_empty_dir(&expanded) {
|
||||
return Ok(Value::nothing(call_span).into_pipeline_data());
|
||||
}
|
||||
p.push("*");
|
||||
|
|
|
@ -25,11 +25,7 @@ pub fn glob_from(
|
|||
ShellError,
|
||||
> {
|
||||
let path = PathBuf::from(&pattern.item);
|
||||
let path = if path.is_relative() {
|
||||
expand_path_with(path, cwd)
|
||||
} else {
|
||||
path
|
||||
};
|
||||
let path = expand_path_with(path, cwd);
|
||||
|
||||
let (prefix, pattern) = if path.to_string_lossy().contains('*') {
|
||||
// Path is a glob pattern => do not check for existence
|
||||
|
|
Loading…
Reference in a new issue