You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.3 KiB
39 lines
1.3 KiB
use std::fmt::Debug; |
|
use std::path::Path; |
|
|
|
pub trait Shell: Debug { |
|
fn path(&self, path: &Path) -> anyhow::Result<String>; |
|
fn set_env_var(&self, name: &str, value: &str) -> String; |
|
fn use_on_cd(&self, config: &crate::config::FnmConfig) -> anyhow::Result<String>; |
|
fn rehash(&self) -> Option<String> { |
|
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<dyn Shell> { |
|
type Err = String; |
|
|
|
fn from_str(s: &str) -> Result<Box<dyn Shell>, 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<Box<dyn Shell>> for clap_complete::Shell { |
|
fn from(shell: Box<dyn Shell>) -> Self { |
|
shell.to_clap_shell() |
|
} |
|
}
|
|
|