diff --git a/src/output.rs b/src/output.rs index 7386341..0e11d08 100644 --- a/src/output.rs +++ b/src/output.rs @@ -15,8 +15,8 @@ use std::ops::Deref; use std::path::{self, Path, PathBuf, Component}; #[cfg(any(unix, target_os = "redox"))] use std::os::unix::fs::PermissionsExt; -#[cfg(windows)] use std::env; +use std::borrow::Cow; use ansi_term; @@ -42,7 +42,7 @@ fn get_separator() -> String { #[cfg(windows)] fn get_separator() -> String { - if let Some(_) = env::var_os("PATH") { + if let Some(_) = env::var_os("HOME") { String::from("/") } else { path::MAIN_SEPARATOR.to_string() @@ -78,7 +78,7 @@ fn print_entry_colorized(path: &Path, config: &FdOptions, ls_colors: &LsColors) Component::RootDir => String::new(), // Everything else uses a separator that is painted the same way as the component. _ => { - style.paint(get_separator()).to_string() + style.paint(get_separator()).to_string() }, }; } @@ -90,11 +90,25 @@ fn print_entry_colorized(path: &Path, config: &FdOptions, ls_colors: &LsColors) } } +#[cfg(not(windows))] +fn write_entry_uncolorized(entry: Cow, separator: str) -> io::Result<()> { + write!(&mut io::stdout(), "{}{}", entry, separator) +} + +#[cfg(windows)] +fn write_entry_uncolorized(entry: Cow, separator: &'static str) -> io::Result<()> { + if let Some(_) = env::var_os("HOME") { + write!(&mut io::stdout(), "{}{}", entry.replace("\\", "/"), separator) + } else { + write!(&mut io::stdout(), "{}{}", entry, separator) + } +} + fn print_entry_uncolorized(path: &Path, config: &FdOptions) -> io::Result<()> { let separator = if config.null_separator { "\0" } else { "\n" }; let path_str = path.to_string_lossy(); - write!(&mut io::stdout(), "{}{}", path_str, separator) + write_entry_uncolorized(path_str, separator) } fn get_path_style<'a>(path: &Path, ls_colors: &'a LsColors) -> Option<&'a ansi_term::Style> {