Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setting to disable kubie's prompt #23

Merged
merged 2 commits into from
Apr 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ configs:

# Prompt settings.
prompt:
# Disable kubie's custom prompt inside of a kubie shell. This is useful
# when you already have a prompt displaying kubernetes information.
# Default: false
disable: true

# When using recursive contexts, show depth when larger than 1.
# Default: true
show_depth: true
Expand Down
3 changes: 3 additions & 0 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ fn default_exclude_path() -> Vec<String> {

#[derive(Debug, Deserialize)]
pub struct Prompt {
#[serde(default = "def_bool_false")]
pub disable: bool,
#[serde(default = "def_bool_true")]
pub show_depth: bool,
#[serde(default = "def_bool_false")]
Expand All @@ -132,6 +134,7 @@ pub struct Prompt {
impl Default for Prompt {
fn default() -> Self {
Prompt {
disable: false,
show_depth: true,
zsh_use_rps1: false,
}
Expand Down
12 changes: 10 additions & 2 deletions src/shell/bash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,21 @@ function __kubie_cmd_pre_exec__() {{
}}

trap '__kubie_cmd_pre_exec__' DEBUG
"#
)?;

if !info.settings.prompt.disable {
write!(
temp_rc_file,
r#"
KUBIE_PROMPT='{}'
PS1="$KUBIE_PROMPT $PS1"
unset KUBIE_PROMPT
"#,
info.prompt,
)?;
info.prompt,
)?;
}

temp_rc_file.flush()?;

let mut cmd = Command::new("bash");
Expand Down
12 changes: 9 additions & 3 deletions src/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ impl<'n> EnvVars<'n> {
}
}

pub struct ShellSpawnInfo<'n> {
pub struct ShellSpawnInfo<'s, 'n> {
settings: &'s Settings,
env_vars: EnvVars<'n>,
prompt: String,
}
Expand All @@ -62,13 +63,17 @@ pub fn spawn_shell(settings: &Settings, config: KubeConfig, session: &Session) -
let next_depth = depth + 1;

let mut env_vars = EnvVars::new();
// pre-insert the KUBECONFIG variable into the shell.
// This will make sure any shell plugins/add-ons which require this env variable will have it available at the beginninng of the .rc file

// Pre-insert the KUBECONFIG variable into the shell.
// This will make sure any shell plugins/add-ons which require this env variable
// will have it available at the beginninng of the .rc file
env_vars.insert("KUBECONFIG", temp_config_file.path());
env_vars.insert("KUBIE_ACTIVE", "1");
env_vars.insert("KUBIE_DEPTH", next_depth.to_string());
env_vars.insert("KUBIE_KUBECONFIG", temp_config_file.path());
env_vars.insert("KUBIE_SESSION", temp_session_file.path());

env_vars.insert("KUBIE_PROMPT_DISABLE", if settings.prompt.disable { "1" } else { "0" });
env_vars.insert(
"KUBIE_ZSH_USE_RPS1",
if settings.prompt.zsh_use_rps1 { "1" } else { "0" },
Expand All @@ -87,6 +92,7 @@ pub fn spawn_shell(settings: &Settings, config: KubeConfig, session: &Session) -
}

let info = ShellSpawnInfo {
settings,
env_vars,
prompt: prompt::generate_ps1(settings, next_depth, kind),
};
Expand Down
11 changes: 9 additions & 2 deletions src/shell/zsh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ function __kubie_cmd_pre_exec__() {{
}}

add-zsh-hook preexec __kubie_cmd_pre_exec__
"#,
)?;

if !info.settings.prompt.disable {
write!(
zshrc,
r#"
# Activate prompt substitution.
setopt PROMPT_SUBST

Expand Down Expand Up @@ -62,8 +68,9 @@ function __kubie_cmd_pre_cmd__() {{
# also add our own precmd hook which modifies PS1 after promptinit themes.
add-zsh-hook precmd __kubie_cmd_pre_cmd__
"#,
info.prompt
)?;
info.prompt
)?;
}
}

let mut cmd = Command::new("zsh");
Expand Down