diff --git a/README.md b/README.md index f1c236d..5b79c58 100644 --- a/README.md +++ b/README.md @@ -314,7 +314,8 @@ Options: -d, --max-depth Set maximum search depth (default: none) -E, --exclude Exclude entries that match the given glob pattern -t, --type Filter by type: file (f), directory (d), symlink (l), - executable (x), empty (e), socket (s), pipe (p) + executable (x), empty (e), socket (s), pipe (p), + block-device (b), char-device (c) -e, --extension Filter by file extension -S, --size Limit results based on the size of files --changed-within Filter by file modification time (newer than) diff --git a/contrib/completion/_fd b/contrib/completion/_fd index b00f897..28826a9 100644 --- a/contrib/completion/_fd +++ b/contrib/completion/_fd @@ -26,6 +26,8 @@ _fd() { {l,symlink}'\:"symbolic links"' {e,empty}'\:"empty files or directories"' {x,executable}'\:"executable (files)"' + {b,block-device}'\:"block devices"' + {c,char-device}'\:"character devices"' {s,socket}'\:"sockets"' {p,pipe}'\:"named pipes (FIFOs)"' ) diff --git a/doc/fd.1 b/doc/fd.1 index 7b0180f..7a28377 100644 --- a/doc/fd.1 +++ b/doc/fd.1 @@ -184,6 +184,10 @@ regular files directories .IP "l, symlink" symbolic links +.IP "b, block-device" +block devices +.IP "c, char-device" +character devices .IP "s, socket" sockets .IP "p, pipe" diff --git a/src/cli.rs b/src/cli.rs index 53d0cbb..af9bcce 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -313,6 +313,8 @@ pub struct Opts { /// {n} 'l' or 'symlink': symbolic links /// {n} 's' or 'socket': socket /// {n} 'p' or 'pipe': named pipe (FIFO) + /// {n} 'b' or 'block-device': block device + /// {n} 'c' or 'char-device': character device /// {n}{n} 'x' or 'executable': executables /// {n} 'e' or 'empty': empty files or directories /// @@ -346,7 +348,8 @@ pub struct Opts { hide_possible_values = true, value_enum, help = "Filter by type: file (f), directory (d), symlink (l), \ - executable (x), empty (e), socket (s), pipe (p)", + executable (x), empty (e), socket (s), pipe (p), \ + char-device (c), block-device (b)", long_help )] pub filetype: Option>, @@ -720,6 +723,10 @@ pub enum FileType { Directory, #[value(alias = "l")] Symlink, + #[value(alias = "b")] + BlockDevice, + #[value(alias = "c")] + CharDevice, /// A file which is executable by the current effective user #[value(alias = "x")] Executable, diff --git a/src/filesystem.rs b/src/filesystem.rs index b7895c0..b9df0ba 100644 --- a/src/filesystem.rs +++ b/src/filesystem.rs @@ -59,6 +59,26 @@ pub fn is_empty(entry: &dir_entry::DirEntry) -> bool { } } +#[cfg(any(unix, target_os = "redox"))] +pub fn is_block_device(ft: fs::FileType) -> bool { + ft.is_block_device() +} + +#[cfg(windows)] +pub fn is_block_device(_: fs::FileType) -> bool { + false +} + +#[cfg(any(unix, target_os = "redox"))] +pub fn is_char_device(ft: fs::FileType) -> bool { + ft.is_char_device() +} + +#[cfg(windows)] +pub fn is_char_device(_: fs::FileType) -> bool { + false +} + #[cfg(any(unix, target_os = "redox"))] pub fn is_socket(ft: fs::FileType) -> bool { ft.is_socket() diff --git a/src/filetypes.rs b/src/filetypes.rs index c34cc49..a10924b 100644 --- a/src/filetypes.rs +++ b/src/filetypes.rs @@ -9,6 +9,8 @@ pub struct FileTypes { pub files: bool, pub directories: bool, pub symlinks: bool, + pub block_devices: bool, + pub char_devices: bool, pub sockets: bool, pub pipes: bool, pub executables_only: bool, @@ -21,6 +23,8 @@ impl FileTypes { (!self.files && entry_type.is_file()) || (!self.directories && entry_type.is_dir()) || (!self.symlinks && entry_type.is_symlink()) + || (!self.block_devices && filesystem::is_block_device(*entry_type)) + || (!self.char_devices && filesystem::is_char_device(*entry_type)) || (!self.sockets && filesystem::is_socket(*entry_type)) || (!self.pipes && filesystem::is_pipe(*entry_type)) || (self.executables_only && !entry.path().executable()) @@ -28,6 +32,8 @@ impl FileTypes { || !(entry_type.is_file() || entry_type.is_dir() || entry_type.is_symlink() + || filesystem::is_block_device(*entry_type) + || filesystem::is_char_device(*entry_type) || filesystem::is_socket(*entry_type) || filesystem::is_pipe(*entry_type)) } else { diff --git a/src/main.rs b/src/main.rs index 8c39a1e..a1bad2b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -269,6 +269,8 @@ fn construct_config(mut opts: Opts, pattern_regexps: &[String]) -> Result file_types.empty_only = true, + BlockDevice => file_types.block_devices = true, + CharDevice => file_types.char_devices = true, Socket => file_types.sockets = true, Pipe => file_types.pipes = true, }