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
Provenance
- Commit
cb56add- Tree
ed9efb2- Author
sharkdp <davidpeter@web.de>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
4287cdd
7 files changed+49 added−8 removed
modified:doc/fd.1+4 added
127 unmodified lines128 .IP "x, executable"129 executable (files)130 .IP "e, empty"131 empty files or directories132+.IP "s, socket"133+sockets134+.IP "p, pipe"135+named pipes (FIFOs)136 .RE137 138 .RS139 This option can be used repeatedly to allow for multiple file types.151 unmodified linesmodified:src/app.rs+8 added-2 removed
226 unmodified lines227 "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 linesmodified:src/filesystem.rs+21 added-1 removed
2 unmodified lines3 use std::ffi::OsStr;4 use std::fs;5 use std::io;6 #[cfg(any(unix, target_os = "redox"))]7-use std::os::unix::fs::PermissionsExt;7+use std::os::unix::fs::{PermissionsExt, FileTypeExt};8 use std::path::{Path, PathBuf};9 10 use crate::walk;11 55 unmodified lines67 }68 }69 70 #[cfg(any(unix, target_os = "redox"))]71+pub fn is_socket(ft: &fs::FileType) -> bool {72+ ft.is_socket()73+}74+75+#[cfg(windows)]76+pub fn is_socket(_: &fs::FileType) -> bool {77+ false78+}79+80+#[cfg(any(unix, target_os = "redox"))]81+pub fn is_pipe(ft: &fs::FileType) -> bool {82+ ft.is_fifo()83+}84+85+#[cfg(windows)]86+pub fn is_pipe(_: &fs::FileType) -> bool {87+ false88+}89+90+#[cfg(any(unix, target_os = "redox"))]91 pub fn osstr_to_bytes(input: &OsStr) -> Cow<[u8]> {92 use std::os::unix::ffi::OsStrExt;93 Cow::Borrowed(input.as_bytes())94 }35 unmodified linesmodified:src/filetypes.rs+4 added
1 unmodified line2 pub 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 lines14 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 linemodified:src/main.rs+3 added-3 removed
315 unmodified lines316 "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 linesmodified:src/walk.rs+7 added-1 removed
388 unmodified lines389 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 linesmodified:CHANGELOG.md+2 added-1 removed
10 unmodified lines11 - 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.20 21 ## Bugfixes22 424 unmodified lines