use std::path::Path;
#[derive(Debug, PartialEq)]
pub enum ShellType {
BASH,
FISH,
UNKNOWN,
ZSH,
}
pub fn get_shell_type(shell_executable_path: &str) -> Result<ShellType, String> {
let shell_type = match Path::new(shell_executable_path).file_stem() {
Some(p) => match p.to_str() {
Some(inner_p) => inner_p,
None => {
return Err(format!(
"could not covert shell type to string for '{}'",
shell_executable_path
));
}
},
None => {
return Err(format!(
"could not extract file stem to determine shell type from '{}'",
shell_executable_path
));
}
};
if shell_type.ends_with("fish") {
return Ok(ShellType::FISH);
}
if shell_type.ends_with("bash") {
return Ok(ShellType::BASH);
}
if shell_type.ends_with("zsh") {
return Ok(ShellType::ZSH);
}
Ok(ShellType::UNKNOWN)
}