Skip to content
Myr

Add new `--type socket` and `--type pipe` filters

Before adoption: this commit came in with the history the project adopted, so no landing records it.

closes #511

authored by sharkdp · committed by David Peter · parent 4287cdd · Browse files · 7 files+49 added−8 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

7 files+49 added−8 removed

  • other:+49 added−8 removed

7 files+49 added−8 removed

modified:doc/fd.1+4 added
127 unmodified lines
128.IP "x, executable"129executable (files)130.IP "e, empty"131empty files or directories132.IP "s, socket"133sockets134.IP "p, pipe"135named pipes (FIFOs)136.RE137138.RS139This option can be used repeatedly to allow for multiple file types.
151 unmodified lines
modified:src/app.rs+8 added-2 removed
226 unmodified lines
227 "x",228 "executable",229 "e",230 "empty",231 "s",232 "socket",233 "p",234 "pipe",235 ])236 .hide_possible_values(true)237 .help(238 "Filter by type: file (f), directory (d), symlink (l),\nexecutable (x), \235 empty (e)",239 empty (e), socket (s), pipe (p)",240 )241 .long_help(242 "Filter the search by type (multiple allowable filetypes can be specified):\n \243 'f' or 'file': regular files\n \244 'd' or 'directory': directories\n \245 'l' or 'symlink': symbolic links\n \246 'x' or 'executable': executables\n \243 'e' or 'empty': empty files or directories",247 'e' or 'empty': empty files or directories\n \248 's' or 'socket': socket\n \249 'p' or 'pipe': named pipe (FIFO)",250 ),251 )252 .arg(253 Arg::with_name("extension")
288 unmodified lines
modified:src/filesystem.rs+21 added-1 removed
2 unmodified lines
3use std::ffi::OsStr;4use std::fs;5use std::io;6#[cfg(any(unix, target_os = "redox"))]7use std::os::unix::fs::PermissionsExt;7use std::os::unix::fs::{PermissionsExt, FileTypeExt};8use std::path::{Path, PathBuf};910use crate::walk;11
55 unmodified lines
67 }68}6970#[cfg(any(unix, target_os = "redox"))]71pub fn is_socket(ft: &fs::FileType) -> bool {72 ft.is_socket()73}7475#[cfg(windows)]76pub fn is_socket(_: &fs::FileType) -> bool {77 false78}7980#[cfg(any(unix, target_os = "redox"))]81pub fn is_pipe(ft: &fs::FileType) -> bool {82 ft.is_fifo()83}8485#[cfg(windows)]86pub fn is_pipe(_: &fs::FileType) -> bool {87 false88}8990#[cfg(any(unix, target_os = "redox"))]91pub fn osstr_to_bytes(input: &OsStr) -> Cow<[u8]> {92 use std::os::unix::ffi::OsStrExt;93 Cow::Borrowed(input.as_bytes())94}
35 unmodified lines
modified:src/filetypes.rs+4 added
1 unmodified line
2pub struct FileTypes {3 pub files: bool,4 pub directories: bool,5 pub symlinks: bool,6 pub sockets: bool,7 pub pipes: bool,8 pub executables_only: bool,9 pub empty_only: bool,10}11
2 unmodified lines
14 FileTypes {15 files: false,16 directories: false,17 symlinks: false,18 sockets: false,19 pipes: false,20 executables_only: false,21 empty_only: false,22 }23 }
1 unmodified line
modified:src/main.rs+3 added-3 removed
315 unmodified lines
316 "x" | "executable" => {317 file_types.executables_only = true;318 file_types.files = true;319 }320 "e" | "empty" => {321 file_types.empty_only = true;322 }320 "e" | "empty" => file_types.empty_only = true,321 "s" | "socket" => file_types.sockets = true,322 "p" | "pipe" => file_types.pipes = true,323 _ => unreachable!(),324 }325 }326
73 unmodified lines
modified:src/walk.rs+7 added-1 removed
388 unmodified lines
389 if let Some(ref entry_type) = entry.file_type() {390 if (!file_types.files && entry_type.is_file())391 || (!file_types.directories && entry_type.is_dir())392 || (!file_types.symlinks && entry_type.is_symlink())393 || (!file_types.sockets && filesystem::is_socket(entry_type))394 || (!file_types.pipes && filesystem::is_pipe(entry_type))395 || (file_types.executables_only396 && !entry397 .metadata()398 .map(|m| filesystem::is_executable(&m))399 .unwrap_or(false))400 || (file_types.empty_only && !filesystem::is_empty(&entry))399 || !(entry_type.is_file() || entry_type.is_dir() || entry_type.is_symlink())401 || !(entry_type.is_file()402 || entry_type.is_dir()403 || entry_type.is_symlink()404 || filesystem::is_socket(entry_type)405 || filesystem::is_pipe(entry_type))406 {407 return ignore::WalkState::Continue;408 }409 } else {
50 unmodified lines
modified:CHANGELOG.md+2 added-1 removed
10 unmodified lines
11- Add a new `--max-results=<count>` option to limit the number of search results, see #472, #476 and #55512 This can be useful to speed up searches in cases where you know that there are only N results.13 Using this option is also (slightly) faster than piping to `head -n <count>` where `fd` can only14 exit when it finds the search results `<count> + 1`.15- Add the alias `-1` for `--max-results=1`, see #561. (@SimplyDanny).16- Add new `--type socket` and `--type pipe` filters, see #511.17- Add new `--min-depth <depth>` and `--exact-depth <depth>` options in addition to the existing option18 to limit the maximum depth. See #404.17- Add the alias `-1` for `--max-results=1`, see #561. (@SimplyDanny).19- Support additional ANSI font styles in `LS_COLORS`: faint, slow blink, rapid blink, dimmed, hidden and strikethrough.2021## Bugfixes22
424 unmodified lines