From acefbc523f984826a34fea2ca5d6a96ca00c7503 Mon Sep 17 00:00:00 2001 From: Jason Wang Date: Thu, 30 Jul 2020 09:57:15 -0700 Subject: [PATCH] feat(conda): add ignore_base option (#1539) * Add ignore_base to conda module * Add ignore_base to conda module in English docs * `ignore_base` defaults to `true` --- docs/config/README.md | 1 + src/configs/conda.rs | 2 ++ src/modules/conda.rs | 4 ++++ tests/testsuite/conda.rs | 19 ++++++++++++++++++- 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/docs/config/README.md b/docs/config/README.md index 5109b4d9..0680ac3c 100644 --- a/docs/config/README.md +++ b/docs/config/README.md @@ -519,6 +519,7 @@ This does not suppress conda's own prompt modifier, you may want to run `conda c | `symbol` | `"🅒 "` | The symbol used before the environment name. | | `style` | `"bold green"` | The style for the module. | | `format` | `"[$symbol$environment]($style) "` | The format for the module. | +| `ignore_base` | `true` | Ignores `base` environment when activated. | | `disabled` | `false` | Disables the `conda` module. | ### Variables diff --git a/src/configs/conda.rs b/src/configs/conda.rs index f05c5bc1..0680380c 100644 --- a/src/configs/conda.rs +++ b/src/configs/conda.rs @@ -8,6 +8,7 @@ pub struct CondaConfig<'a> { pub format: &'a str, pub symbol: &'a str, pub style: &'a str, + pub ignore_base: bool, pub disabled: bool, } @@ -18,6 +19,7 @@ impl<'a> RootModuleConfig<'a> for CondaConfig<'a> { format: "via [$symbol$environment]($style) ", symbol: "🅒 ", style: "green bold", + ignore_base: true, disabled: false, } } diff --git a/src/modules/conda.rs b/src/modules/conda.rs index 635e8f35..4d564176 100644 --- a/src/modules/conda.rs +++ b/src/modules/conda.rs @@ -19,6 +19,10 @@ pub fn module<'a>(context: &'a Context) -> Option> { let mut module = context.new_module("conda"); let config: CondaConfig = CondaConfig::try_load(module.config); + if config.ignore_base && conda_env == "base" { + return None; + } + let conda_env = truncate(conda_env, config.truncation_length); let parsed = StringFormatter::new(config.format).and_then(|formatter| { diff --git a/tests/testsuite/conda.rs b/tests/testsuite/conda.rs index 7a6ed7be..985b634a 100644 --- a/tests/testsuite/conda.rs +++ b/tests/testsuite/conda.rs @@ -1,7 +1,7 @@ use ansi_term::Color; use std::io; -use crate::common; +use crate::common::{self, TestCommand}; #[test] fn not_in_env() -> io::Result<()> { @@ -14,6 +14,23 @@ fn not_in_env() -> io::Result<()> { Ok(()) } +#[test] +fn ignore_base() -> io::Result<()> { + let output = common::render_module("conda") + .env("CONDA_DEFAULT_ENV", "base") + .use_config(toml::toml! { + [conda] + ignore_base = true + }) + .output()?; + + let expected = ""; + let actual = String::from_utf8(output.stdout).unwrap(); + + assert_eq!(expected, actual); + Ok(()) +} + #[test] fn env_set() -> io::Result<()> { let output = common::render_module("conda")