1use std::path::Path;
2
3#[derive(Debug, PartialEq)]
4pub enum ShellType {
5 BASH,
6 FISH,
7 UNKNOWN,
8 ZSH,
9}
10
11pub fn get_shell_type(shell_executable_path: &str) -> Result<ShellType, String> {
20 let shell_type = match Path::new(shell_executable_path).file_stem() {
22 Some(p) => match p.to_str() {
23 Some(inner_p) => inner_p,
24 None => {
25 return Err(format!(
26 "could not covert shell type to string for '{}'",
27 shell_executable_path
28 ));
29 }
30 },
31 None => {
32 return Err(format!(
33 "could not extract file stem to determine shell type from '{}'",
34 shell_executable_path
35 ));
36 }
37 };
38
39 if shell_type.ends_with("fish") {
40 return Ok(ShellType::FISH);
41 }
42
43 if shell_type.ends_with("bash") {
44 return Ok(ShellType::BASH);
45 }
46
47 if shell_type.ends_with("zsh") {
48 return Ok(ShellType::ZSH);
49 }
50
51 Ok(ShellType::UNKNOWN)
52}