diff --git a/crates/nu-cli/src/shell/filesystem_shell.rs b/crates/nu-cli/src/shell/filesystem_shell.rs index bfe7cec53..22ff18408 100644 --- a/crates/nu-cli/src/shell/filesystem_shell.rs +++ b/crates/nu-cli/src/shell/filesystem_shell.rs @@ -9,6 +9,7 @@ use crate::prelude::*; use crate::shell::completer::NuCompleter; use crate::shell::shell::Shell; use crate::utils::FileStructure; +use cfg_if::cfg_if; use nu_errors::ShellError; use nu_parser::ExpandContext; use nu_protocol::{Primitive, ReturnSuccess, UntaggedValue}; @@ -1135,3 +1136,23 @@ fn is_dir_empty(d: &PathBuf) -> bool { Ok(mut s) => s.next().is_none(), } } + +fn is_hidden_dir(dir: impl AsRef) -> bool { + cfg_if! { + if #[cfg(unix)] { + dir.as_ref().starts_with(".") + } else if #[cfg(windows)] { + use std::os::windows::fs::MetadataExt; + + if let Ok(metadata) = dir.as_ref().metadata() { + let attributes = metadata.file_attributes(); + // https://docs.microsoft.com/en-us/windows/win32/fileio/file-attribute-constants + attributes & 0x2 + } else { + false + } + } else { + false + } + } +}