use clap::ValueEnum;
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
#[allow(clippy::enum_variant_names)]
pub(crate) enum Shell {
Bash,
Zsh,
Fish,
#[value(name = "powershell", alias = "pwsh")]
PowerShell,
}
pub(crate) const MARKER_BEGIN: &str = "# >>> lightshuttle alias >>>";
pub(crate) const MARKER_END: &str = "# <<< lightshuttle alias <<<";
impl Shell {
pub(crate) fn detect() -> Option<Self> {
if cfg!(windows) {
return Some(Self::PowerShell);
}
let shell = std::env::var("SHELL").ok()?;
let name = shell.rsplit(['/', '\\']).next().unwrap_or(&shell);
match name {
n if n.contains("bash") => Some(Self::Bash),
n if n.contains("zsh") => Some(Self::Zsh),
n if n.contains("fish") => Some(Self::Fish),
_ => None,
}
}
pub(crate) fn alias_line(self) -> String {
match self {
Self::Bash | Self::Zsh => "alias lsh='lightshuttle'".to_owned(),
Self::Fish => "alias lsh 'lightshuttle'".to_owned(),
Self::PowerShell => "Set-Alias lsh lightshuttle".to_owned(),
}
}
pub(crate) fn label(self) -> &'static str {
match self {
Self::Bash => "bash",
Self::Zsh => "zsh",
Self::Fish => "fish",
Self::PowerShell => "PowerShell",
}
}
}