Add path-separator option.
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Example usage: `fd.exe --path-separator /` on windows.
authored by Nathan Moreau · committed by David Peter · parent 1d16cd8 · Browse files · 4 files·+43 added−1 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+43 added−1 removed
- other:+43 added−1 removed
Provenance
- Commit
24e108e- Tree
eddc68c- Author
Nathan Moreau <nathan.moreau@m4x.org>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
1d16cd8
4 files changed+43 added−1 removed
modified:src/internal/opts.rs+3 added
73 unmodified lines74 pub time_constraints: Vec<TimeFilter>,75 76 /// Whether or not to display filesystem errors77 pub show_filesystem_errors: bool,78+79+ /// The separator used to print file paths.80+ pub path_separator: Option<u8>,81 }modified:src/app.rs+10 added
205 unmodified lines206 .long("show-errors")207 .hidden_short_help(true),208 )209 .arg(arg("pattern"))210+ .arg(211+ arg("path-separator")212+ .takes_value(true)213+ .long("path-separator")214+ .number_of_values(1),215+ )216 .arg(arg("path").multiple(true))217 .arg(218 arg("search-path")219 .long("search-path")34 unmodified lines254 , "Treat the pattern as a literal string instead of a regular expression.");255 doc!(h, "absolute-path"256 , "Show absolute instead of relative paths"257 , "Shows the full path starting from the root as opposed to relative paths.");258+ doc!(h, "path-separator"259+ , "Set the path separator to use when printing file paths."260+ , "Set the path separator to use when printing file paths. \261+ A path separator is limited to a single byte.");262 doc!(h, "follow"263 , "Follow symbolic links"264 , "By default, fd does not descend into symlinked directories. Using this flag, symbolic \265 links are also traversed.");124 unmodified linesmodified:src/main.rs+15 added
112 unmodified lines113 Some("never") => false,114 _ => atty::is(Stream::Stdout),115 };116 117+ let path_separator: Option<u8> = match matches.value_of("path-separator") {118+ Some(sep_str) => {119+ let sep = sep_str.as_bytes();120+ if sep.len() != 1 {121+ print_error_and_exit!(122+ "'{}' is not a valid path separator. See 'fd --help'.",123+ sep_str124+ );125+ }126+ Some(sep[0])127+ }128+ None => None,129+ };130+131 #[cfg(windows)]132 let colored_output = colored_output && ansi_term::enable_ansi_support().is_ok();133 134 let ls_colors = if colored_output {122 unmodified lines257 .unwrap_or_else(|| vec![]),258 size_constraints: size_limits,259 time_constraints,260 show_filesystem_errors: matches.is_present("show-errors"),261+ path_separator,262 };263 264 match RegexBuilder::new(&pattern_regex)265 .case_insensitive(!config.case_sensitive)16 unmodified linesmodified:src/output.rs+15 added-1 removed
65 unmodified lines66 let style = style67 .map(Style::to_ansi_term_style)68 .unwrap_or(default_style);69 70- write!(stdout, "{}", style.paint(component.to_string_lossy()))?;70+ let path_string = component.to_string_lossy();71 72+ match config.path_separator {73+ None => write!(stdout, "{}", style.paint(path_string))?,74+ Some(sep) => {75+ let mut path_bytes = path_string.as_bytes().to_vec();76+ for b in &mut path_bytes {77+ if *b == b'/' || (cfg!(windows) && *b == b'\\') {78+ *b = sep;79+ }80+ }81+ let path_string = String::from_utf8_lossy(&path_bytes);82+ write!(stdout, "{}", style.paint(path_string))?83+ }84+ }85+86 if wants_to_quit.load(Ordering::Relaxed) {87 writeln!(stdout)?;88 process::exit(ExitCode::KilledBySigint.into());89 }19 unmodified lines