mirror of
https://github.com/sharkdp/fd.git
synced 2024-11-17 17:35:16 +01:00
parent
ab3ded8d27
commit
b1e48efc4a
5 changed files with 9 additions and 4 deletions
|
@ -83,7 +83,7 @@ pub fn build_app() -> App<'static, 'static> {
|
|||
.number_of_values(1)
|
||||
.takes_value(true)
|
||||
.value_name("filetype")
|
||||
.possible_values(&["f", "file", "d", "directory", "l", "symlink"])
|
||||
.possible_values(&["f", "file", "d", "directory", "l", "symlink", "x", "executable"])
|
||||
.hide_possible_values(true),
|
||||
)
|
||||
.arg(
|
||||
|
@ -189,7 +189,8 @@ fn usage() -> HashMap<&'static str, Help> {
|
|||
, "Filter the search by type (multiple allowable filetypes can be specified):\n \
|
||||
'f' or 'file': regular files\n \
|
||||
'd' or 'directory': directories\n \
|
||||
'l' or 'symlink': symbolic links");
|
||||
'l' or 'symlink': symbolic links\n \
|
||||
'x' or 'executable': executables");
|
||||
doc!(h, "extension"
|
||||
, "Filter by file extension"
|
||||
, "(Additionally) filter search results by their file extension. Multiple allowable file \
|
||||
|
|
|
@ -22,6 +22,7 @@ pub struct FileTypes {
|
|||
pub files: bool,
|
||||
pub directories: bool,
|
||||
pub symlinks: bool,
|
||||
pub executables: bool,
|
||||
}
|
||||
|
||||
impl Default for FileTypes {
|
||||
|
@ -30,6 +31,7 @@ impl Default for FileTypes {
|
|||
files: false,
|
||||
directories: false,
|
||||
symlinks: false,
|
||||
executables: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -161,6 +161,7 @@ fn main() {
|
|||
"f" | "file" => file_types.files = true,
|
||||
"d" | "directory" => file_types.directories = true,
|
||||
"l" | "symlink" => file_types.symlinks = true,
|
||||
"x" | "executable" => file_types.executables = true,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -135,11 +135,11 @@ fn get_path_style<'a>(path: &Path, ls_colors: &'a LsColors) -> Option<&'a ansi_t
|
|||
}
|
||||
|
||||
#[cfg(any(unix, target_os = "redox"))]
|
||||
fn is_executable(md: &fs::Metadata) -> bool {
|
||||
pub fn is_executable(md: &fs::Metadata) -> bool {
|
||||
md.permissions().mode() & 0o111 != 0
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn is_executable(_: &fs::Metadata) -> bool {
|
||||
pub fn is_executable(_: &fs::Metadata) -> bool {
|
||||
false
|
||||
}
|
||||
|
|
|
@ -201,6 +201,7 @@ pub fn scan(path_vec: &[PathBuf], pattern: Arc<Regex>, config: Arc<FdOptions>) {
|
|||
if (entry_type.is_file() && !file_types.files)
|
||||
|| (entry_type.is_dir() && !file_types.directories)
|
||||
|| (entry_type.is_symlink() && !file_types.symlinks)
|
||||
|| (output::is_executable(&entry.metadata().unwrap()) && !file_types.executables)
|
||||
{
|
||||
return ignore::WalkState::Continue;
|
||||
} else if !(entry_type.is_file() || entry_type.is_dir()
|
||||
|
|
Loading…
Reference in a new issue