Added windows specific logic to check if we're in a unix like shell

This commit is contained in:
Dock O'Neal 2017-11-21 22:28:06 -05:00
parent 44ee5a0b85
commit 062ba4b8ae
1 changed files with 19 additions and 1 deletions

View File

@ -15,6 +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 ansi_term;
@ -33,6 +35,20 @@ pub fn print_entry(entry: &PathBuf, config: &FdOptions) {
}
}
#[cfg(not(windows))]
fn get_separator() -> String {
path::MAIN_SEPARATOR.to_string()
}
#[cfg(windows)]
fn get_separator() -> String {
if let Some(_) = env::var_os("PATH") {
String::from("/")
} else {
path::MAIN_SEPARATOR.to_string()
}
}
fn print_entry_colorized(path: &Path, config: &FdOptions, ls_colors: &LsColors) -> io::Result<()> {
let default_style = ansi_term::Style::default();
@ -61,7 +77,9 @@ fn print_entry_colorized(path: &Path, config: &FdOptions, ls_colors: &LsColors)
// RootDir is already a separator.
Component::RootDir => String::new(),
// Everything else uses a separator that is painted the same way as the component.
_ => style.paint(path::MAIN_SEPARATOR.to_string()).to_string(),
_ => {
style.paint(get_separator()).to_string()
},
};
}