Skip to content

Commit

Permalink
Addresses sharkdp#246
Browse files Browse the repository at this point in the history
Some implementation to search by filetype `executables`
  • Loading branch information
PramodBisht committed Mar 8, 2018
1 parent 3386b85 commit 8f796e3
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,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(
Expand Down Expand Up @@ -186,7 +186,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 \
Expand Down
2 changes: 2 additions & 0 deletions src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub struct FileTypes {
pub files: bool,
pub directories: bool,
pub symlinks: bool,
pub executables: bool,
}

impl Default for FileTypes {
Expand All @@ -29,6 +30,7 @@ impl Default for FileTypes {
files: false,
directories: false,
symlinks: false,
executables: false,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,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!(),
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
1 change: 1 addition & 0 deletions src/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 8f796e3

Please sign in to comment.