From 57988643ab7abd9f79b1a20c9d8b61365bbf5eff Mon Sep 17 00:00:00 2001 From: anb Date: Mon, 25 Mar 2024 14:33:55 -0700 Subject: [PATCH] add basic support for Elvish Elvish's syntax is not compatible with other POSIX shells, the prompt is generated more dynamically. For now I think it's better to leave it to the users to decide what to put inside the prompt. --- src/shell/detect.rs | 2 ++ src/shell/elvish.rs | 11 +++++++++++ src/shell/mod.rs | 5 +++++ 3 files changed, 18 insertions(+) create mode 100644 src/shell/elvish.rs diff --git a/src/shell/detect.rs b/src/shell/detect.rs index c0f50213..0ce427ba 100644 --- a/src/shell/detect.rs +++ b/src/shell/detect.rs @@ -6,6 +6,7 @@ use anyhow::{anyhow, Context, Result}; #[derive(Copy, Clone, Debug, PartialEq, Eq)] pub enum ShellKind { Bash, + Elvish, Fish, Xonsh, Zsh, @@ -16,6 +17,7 @@ impl ShellKind { pub fn from_str(name: &str) -> Option { Some(match name { "bash" | "dash" => ShellKind::Bash, + "elvish" => ShellKind::Elvish, "fish" => ShellKind::Fish, "xonsh" | "python" => ShellKind::Xonsh, "zsh" => ShellKind::Zsh, diff --git a/src/shell/elvish.rs b/src/shell/elvish.rs new file mode 100644 index 00000000..7ee9ba03 --- /dev/null +++ b/src/shell/elvish.rs @@ -0,0 +1,11 @@ +use anyhow::Result; +use std::process::Command; + +use crate::shell::ShellSpawnInfo; + +pub fn spawn_shell(info: &ShellSpawnInfo) -> Result<()> { + let mut cmd = Command::new("elvish"); + info.env_vars.apply(&mut cmd); + let _ = cmd.status()?; + Ok(()) +} diff --git a/src/shell/mod.rs b/src/shell/mod.rs index 1cbe66d6..7e34f7c3 100644 --- a/src/shell/mod.rs +++ b/src/shell/mod.rs @@ -13,6 +13,7 @@ use crate::vars; mod bash; mod detect; +mod elvish; mod fish; mod nu; mod prompt; @@ -100,6 +101,9 @@ pub fn spawn_shell(settings: &Settings, config: KubeConfig, session: &Session) - ShellKind::Bash => { env_vars.insert("KUBIE_SHELL", "bash"); } + ShellKind::Elvish => { + env_vars.insert("KUBIE_SHELL", "elvish"); + } ShellKind::Fish => { env_vars.insert("KUBIE_SHELL", "fish"); } @@ -122,6 +126,7 @@ pub fn spawn_shell(settings: &Settings, config: KubeConfig, session: &Session) - match kind { ShellKind::Bash => bash::spawn_shell(&info), + ShellKind::Elvish => elvish::spawn_shell(&info), ShellKind::Fish => fish::spawn_shell(&info), ShellKind::Xonsh => xonsh::spawn_shell(&info), ShellKind::Zsh => zsh::spawn_shell(&info),