Skip to content
Myr

set default path separator to '/' in MSYS

Before adoption: this commit came in with the history the project adopted, so no landing records it.

MSYS and MSYS2 environments (such as Git Bash) have a UNIX like filesystem which uses '/' as the path separator rather than '\', but Rust doesn't know about this by default. On Windows, check the MSYSTEM environment variable and set the default value of the --path-separator option to '/' for convenience. There is no similar detection of Cygwin because there seems to be no way for Rust (and any native Win32) programs to detect that they're being called from a Cygwin environment. Cygwin users can use a shell alias/function/script to wrap fd.

authored by Allen Wild · committed by David Peter · parent cf7dd43 · Browse files · 2 files+22 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Fixes: https://github.com/sharkdp/fd/issues/537

Diff stats

2 files+22 added−3 removed

  • other:+22 added−3 removed

2 files+22 added−3 removed

modified:src/filesystem.rs+19 added-2 removed
1use std::borrow::Cow;2use std::env::current_dir;2use std::env;3use std::ffi::OsStr;4use std::fs;5use std::io;6#[cfg(any(unix, target_os = "redox"))]
7 unmodified lines
14 return Ok(path.to_path_buf());15 }1617 let path = path.strip_prefix(".").unwrap_or(path);18 current_dir().map(|path_buf| path_buf.join(path))18 env::current_dir().map(|path_buf| path_buf.join(path))19}2021pub fn absolute_path(path: &Path) -> io::Result<PathBuf> {22 let path_buf = path_absolute_form(path)?;
84 unmodified lines
107pub fn strip_current_dir(path: &Path) -> &Path {108 path.strip_prefix(".").unwrap_or(path)109}110111/// Default value for the path_separator, mainly for MSYS/MSYS2, which set the MSYSTEM112/// environment variable, and we set fd's path separator to '/' rather than Rust's default of '\'.113///114/// Returns Some to use a nonstandard path separator, or None to use rust's default on the target115/// platform.116pub fn default_path_separator() -> Option<String> {117 if cfg!(windows) {118 let msystem = env::var("MSYSTEM").ok()?;119 match msystem.as_str() {120 "MINGW64" | "MINGW32" | "MSYS" => Some("/".to_owned()),121 _ => None,122 }123 } else {124 None125 }126}127128#[cfg(test)]129mod tests {130 use super::strip_current_dir;131 use std::path::Path;
15 unmodified lines
modified:src/main.rs+3 added-1 removed
171 unmodified lines
172 Some("never") => false,173 _ => ansi_colors_support && env::var_os("NO_COLOR").is_none() && interactive_terminal,174 };175176 let path_separator = matches.value_of("path-separator").map(|str| str.to_owned());176 let path_separator = matches177 .value_of("path-separator")178 .map_or_else(filesystem::default_path_separator, |s| Some(s.to_owned()));179180 let ls_colors = if colored_output {181 Some(LsColors::from_env().unwrap_or_else(|| LsColors::from_string(DEFAULT_LS_COLORS)))182 } else {
292 unmodified lines