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`
This commit is contained in:
Jason Wang 2020-07-30 09:57:15 -07:00 committed by GitHub
parent fbaeef8589
commit acefbc523f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 1 deletions

View File

@ -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. | | `symbol` | `"🅒 "` | The symbol used before the environment name. |
| `style` | `"bold green"` | The style for the module. | | `style` | `"bold green"` | The style for the module. |
| `format` | `"[$symbol$environment]($style) "` | The format 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. | | `disabled` | `false` | Disables the `conda` module. |
### Variables ### Variables

View File

@ -8,6 +8,7 @@ pub struct CondaConfig<'a> {
pub format: &'a str, pub format: &'a str,
pub symbol: &'a str, pub symbol: &'a str,
pub style: &'a str, pub style: &'a str,
pub ignore_base: bool,
pub disabled: bool, pub disabled: bool,
} }
@ -18,6 +19,7 @@ impl<'a> RootModuleConfig<'a> for CondaConfig<'a> {
format: "via [$symbol$environment]($style) ", format: "via [$symbol$environment]($style) ",
symbol: "🅒 ", symbol: "🅒 ",
style: "green bold", style: "green bold",
ignore_base: true,
disabled: false, disabled: false,
} }
} }

View File

@ -19,6 +19,10 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
let mut module = context.new_module("conda"); let mut module = context.new_module("conda");
let config: CondaConfig = CondaConfig::try_load(module.config); 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 conda_env = truncate(conda_env, config.truncation_length);
let parsed = StringFormatter::new(config.format).and_then(|formatter| { let parsed = StringFormatter::new(config.format).and_then(|formatter| {

View File

@ -1,7 +1,7 @@
use ansi_term::Color; use ansi_term::Color;
use std::io; use std::io;
use crate::common; use crate::common::{self, TestCommand};
#[test] #[test]
fn not_in_env() -> io::Result<()> { fn not_in_env() -> io::Result<()> {
@ -14,6 +14,23 @@ fn not_in_env() -> io::Result<()> {
Ok(()) 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] #[test]
fn env_set() -> io::Result<()> { fn env_set() -> io::Result<()> {
let output = common::render_module("conda") let output = common::render_module("conda")