Skip to content

Commit

Permalink
add basic support for Elvish
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
xofyarg committed Mar 25, 2024
1 parent fbafa06 commit 5798864
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/shell/detect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use anyhow::{anyhow, Context, Result};
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum ShellKind {
Bash,
Elvish,
Fish,
Xonsh,
Zsh,
Expand All @@ -16,6 +17,7 @@ impl ShellKind {
pub fn from_str(name: &str) -> Option<ShellKind> {
Some(match name {
"bash" | "dash" => ShellKind::Bash,
"elvish" => ShellKind::Elvish,
"fish" => ShellKind::Fish,
"xonsh" | "python" => ShellKind::Xonsh,
"zsh" => ShellKind::Zsh,
Expand Down
11 changes: 11 additions & 0 deletions src/shell/elvish.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
5 changes: 5 additions & 0 deletions src/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::vars;

mod bash;
mod detect;
mod elvish;
mod fish;
mod nu;
mod prompt;
Expand Down Expand Up @@ -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");
}
Expand All @@ -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),
Expand Down

0 comments on commit 5798864

Please sign in to comment.