pub fn zsh() -> Result<(), &'static str> {
let shell = std::env::var("SHELL").unwrap_or_default();
let name = shell.rsplit(['/', '\\']).next().unwrap_or("");
match name {
"zsh" => Ok(()),
"bash" | "sh" | "dash" | "ksh" | "mksh" | "ash" => {
Err("the tool's shell is bash, which passes an unmatched glob through as text")
}
"fish" | "" => {
if cfg!(target_os = "macos") {
Ok(())
} else {
Err("the tool's shell is not known to be zsh")
}
}
_ => Err("the tool's shell is not known to be zsh"),
}
}
pub fn has_glob(text: &str) -> bool {
if text.contains('*') || text.contains('?') {
return true;
}
matches!((text.find('['), text.rfind(']')), (Some(open), Some(close)) if open < close)
}