use std::fmt::Debug; use std::path::Path; pub trait Shell: Debug { fn path(&self, path: &Path) -> anyhow::Result; fn set_env_var(&self, name: &str, value: &str) -> String; fn use_on_cd(&self, config: &crate::config::FnmConfig) -> anyhow::Result; fn rehash(&self) -> Option { None } fn to_clap_shell(&self) -> clap_complete::Shell; } #[cfg(windows)] pub const AVAILABLE_SHELLS: &[&str; 5] = &["cmd", "powershell", "bash", "zsh", "fish"]; #[cfg(unix)] pub const AVAILABLE_SHELLS: &[&str; 4] = &["bash", "zsh", "fish", "powershell"]; impl std::str::FromStr for Box { type Err = String; fn from_str(s: &str) -> Result, Self::Err> { match s { "cmd" => Ok(Box::from(super::windows_cmd::WindowsCmd)), "zsh" => Ok(Box::from(super::zsh::Zsh)), "bash" => Ok(Box::from(super::bash::Bash)), "fish" => Ok(Box::from(super::fish::Fish)), "powershell" => Ok(Box::from(super::powershell::PowerShell)), shell_type => Err(format!("I don't know the shell type of {shell_type:?}",)), } } } impl From> for clap_complete::Shell { fn from(shell: Box) -> Self { shell.to_clap_shell() } }