diff options
Diffstat (limited to 'crates/client/src/atuin_common/shell.rs')
| -rw-r--r-- | crates/client/src/atuin_common/shell.rs | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/crates/client/src/atuin_common/shell.rs b/crates/client/src/atuin_common/shell.rs new file mode 100644 index 00000000..880ff00f --- /dev/null +++ b/crates/client/src/atuin_common/shell.rs @@ -0,0 +1,52 @@ +#[derive(PartialEq)] +pub(crate) enum Shell { + Sh, + Bash, + Fish, + Zsh, + Xonsh, + Nu, + Powershell, + + Unknown, +} + +impl std::fmt::Display for Shell { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let shell = match self { + Self::Bash => "bash", + Self::Fish => "fish", + Self::Zsh => "zsh", + Self::Nu => "nu", + Self::Xonsh => "xonsh", + Self::Sh => "sh", + Self::Powershell => "powershell", + + Self::Unknown => "unknown", + }; + + write!(f, "{shell}") + } +} + +impl Shell { + pub(crate) fn from_env() -> Self { + std::env::var("ATUIN_SHELL").map_or(Self::Unknown, |shell| { + Self::from_string(shell.trim().to_lowercase().as_str()) + }) + } + + pub(crate) fn from_string(name: &str) -> Self { + match name { + "bash" => Self::Bash, + "fish" => Self::Fish, + "zsh" => Self::Zsh, + "xonsh" => Self::Xonsh, + "nu" => Self::Nu, + "sh" => Self::Sh, + "powershell" => Self::Powershell, + + _ => Self::Unknown, + } + } +} |
