diff --git a/src/main.rs b/src/main.rs index 80e380fe9..cffce2a14 100644 --- a/src/main.rs +++ b/src/main.rs @@ -149,18 +149,25 @@ fn set_working_dir(opts: &Opts) -> Result<()> { fn ensure_search_pattern_is_not_a_path(opts: &Opts) -> Result<()> { if !opts.full_path && opts.pattern.contains(std::path::MAIN_SEPARATOR) - && Path::new(&opts.pattern).is_dir() + && (!cfg!(windows) || Path::new(&opts.pattern).is_dir()) { - Err(anyhow!( + let pattern = &opts.pattern; + let sep = std::path::MAIN_SEPARATOR; + let mut message = format!( "The search pattern '{pattern}' contains a path-separation character ('{sep}') \ - and will not lead to any search results.\n\n\ - If you want to search for all files inside the '{pattern}' directory, use a match-all pattern:\n\n \ - fd . '{pattern}'\n\n\ - Instead, if you want your pattern to match the full file path, use:\n\n \ - fd --full-path '{pattern}'", - pattern = &opts.pattern, - sep = std::path::MAIN_SEPARATOR, - )) + and will not lead to any search results.\n" + ); + if Path::new(pattern).is_dir() { + message += &format!( + "\nIf you want to search for all files inside the '{pattern}' directory, \ + use a match-all pattern:\n\n fd . '{pattern}'\n" + ); + } + message += &format!( + "\nIf you want your pattern to match the full file path, use:\n\n \ + fd --full-path '{pattern}'" + ); + Err(anyhow!(message)) } else { Ok(()) }