From b637e437f302c94897bebce15dd4de90468bf830 Mon Sep 17 00:00:00 2001 From: Mick Hohmann Date: Sun, 21 May 2023 17:32:44 +0200 Subject: [PATCH 1/9] Added hostname.detect_env_vars based on the newly added context::detect_env_vars - extended context::detect_env_vars to check for negated environment variables as well, analogous to the other detect modules - made hostname.detect_env_vars only active if ssh_only is set to false for backwards compatibility Co-authored-by: Dominik Sander --- docs/config/README.md | 37 ++++++++++++---- src/configs/hostname.rs | 2 + src/context.rs | 17 ++++++- src/modules/hostname.rs | 98 ++++++++++++++++++++++++++++++++++++++++- 4 files changed, 142 insertions(+), 12 deletions(-) diff --git a/docs/config/README.md b/docs/config/README.md index 1007c1c79dcf..a718ef675dcc 100644 --- a/docs/config/README.md +++ b/docs/config/README.md @@ -2200,16 +2200,22 @@ format = 'via [⎈ $version](bold white) ' The `hostname` module shows the system hostname. +::: warning + +The `detect_env_vars` is only recognized, if `ssh_only` is set to `false`. +You can still check for a ssh connection, add `SSH_CONNECTION` to `detect_env_vars`. + ### Options -| Option | Default | Description | -| ------------ | -------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ | -| `ssh_only` | `true` | Only show hostname when connected to an SSH session. | -| `ssh_symbol` | `'🌐 '` | A format string representing the symbol when connected to SSH session. | -| `trim_at` | `'.'` | String that the hostname is cut off at, after the first match. `'.'` will stop after the first dot. `''` will disable any truncation | -| `format` | `'[$ssh_symbol$hostname]($style) in '` | The format for the module. | -| `style` | `'bold dimmed green'` | The style for the module. | -| `disabled` | `false` | Disables the `hostname` module. | +| Option | Default | Description | +| ----------------- | -------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- | +| `ssh_only` | `true` | Only show hostname when connected to an SSH session. | +| `ssh_symbol` | `'🌐 '` | A format string representing the symbol when connected to SSH session. | +| `trim_at` | `'.'` | String that the hostname is cut off at, after the first match. `'.'` will stop after the first dot. `''` will disable any truncation. | +| `detect_env_vars` | `[]` | Which environment variable(s) should trigger this module. | +| `format` | `'[$ssh_symbol$hostname]($style) in '` | The format for the module. | +| `style` | `'bold dimmed green'` | The style for the module. | +| `disabled` | `false` | Disables the `hostname` module. | ### Variables @@ -2221,7 +2227,9 @@ The `hostname` module shows the system hostname. *: This variable can only be used as a part of a style string -### Example +### Examples + +#### Always show the hostname ```toml # ~/.config/starship.toml @@ -2233,6 +2241,17 @@ trim_at = '.companyname.com' disabled = false ``` +#### Hide the hostname in remote tmux sessions + +```toml +# ~/.config/starship.toml + +[hostname] +ssh_only = false +detect_env_vars = ['!tmux', 'SSH_CONNECTION'] +disabled = false +``` + ## Java The `java` module shows the currently installed version of [Java](https://www.oracle.com/java/). diff --git a/src/configs/hostname.rs b/src/configs/hostname.rs index b6fbfb481ef2..a3c944db539f 100644 --- a/src/configs/hostname.rs +++ b/src/configs/hostname.rs @@ -11,6 +11,7 @@ pub struct HostnameConfig<'a> { pub ssh_only: bool, pub ssh_symbol: &'a str, pub trim_at: &'a str, + pub detect_env_vars: Vec<&'a str>, pub format: &'a str, pub style: &'a str, pub disabled: bool, @@ -22,6 +23,7 @@ impl<'a> Default for HostnameConfig<'a> { ssh_only: true, ssh_symbol: "🌐 ", trim_at: ".", + detect_env_vars: vec![], format: "[$ssh_symbol$hostname]($style) in ", style: "green dimmed bold", disabled: false, diff --git a/src/context.rs b/src/context.rs index 124b5ced1158..9b53923f1b8c 100644 --- a/src/context.rs +++ b/src/context.rs @@ -235,8 +235,23 @@ impl<'a> Context<'a> { disabled == Some(true) } + /// Returns true when no negated environment variable is defined in `env_vars` + /// or none of the negated variables is set in the environment. + pub fn has_no_negative_env_vars(&self, env_vars: &'a [&'a str]) -> bool { + !env_vars + .iter() + .any(|env_var| env_var.starts_with('!') && self.get_env(&env_var[1..]).is_some()) + } + + /// Returns true if 'detect_env_vars' is empty, + /// or if at least one environment variable is set and no negated environment variable is set pub fn detect_env_vars(&'a self, env_vars: &'a [&'a str]) -> bool { - env_vars.is_empty() || (env_vars.iter().any(|e| self.get_env(e).is_some())) + // old + // env_vars.is_empty() || (env_vars.iter().any(|e| self.get_env(e).is_some())) + // new + env_vars.is_empty() + || ((env_vars.iter().any(|e| self.get_env(e).is_some())) + && self.has_no_negative_env_vars(env_vars)) } // returns a new ScanDir struct with reference to current dir_files of context diff --git a/src/modules/hostname.rs b/src/modules/hostname.rs index d476dcf442e9..1c379fa0acc5 100644 --- a/src/modules/hostname.rs +++ b/src/modules/hostname.rs @@ -8,14 +8,20 @@ use crate::formatter::StringFormatter; /// Creates a module with the system hostname /// /// Will display the hostname if all of the following criteria are met: -/// - hostname.disabled is absent or false +/// - `hostname.disabled` is absent or false /// - `hostname.ssh_only` is false OR the user is currently connected as an SSH session (`$SSH_CONNECTION`) +/// - `hostname.ssh_only` is false AND `hostname.detect_env_vars` is either empty or contains a defined environment variable pub fn module<'a>(context: &'a Context) -> Option> { let mut module = context.new_module("hostname"); let config: HostnameConfig = HostnameConfig::try_load(module.config); let ssh_connection = context.get_env("SSH_CONNECTION"); - if config.ssh_only && ssh_connection.is_none() { + if config.ssh_only { + if ssh_connection.is_none() { + return None; + } + // check for environment variables + } else if !(context.detect_env_vars(&config.detect_env_vars)) { return None; } @@ -95,6 +101,92 @@ mod tests { }; } + #[test] + fn ssh_only_false_with_matching_env_var() { + let hostname = get_hostname!(); + let actual = ModuleRenderer::new("hostname") + .config(toml::toml! { + [hostname] + ssh_only = false + trim_at = "" + detect_env_vars = ["FORCE_HOSTNAME"] + }) + .env("FORCE_HOSTNAME", "true") + .collect(); + + let expected = Some(format!("{} in ", style().paint(hostname))); + assert_eq!(expected, actual); + } + + #[test] + fn ssh_only_false_without_matching_env_var() { + let actual = ModuleRenderer::new("hostname") + .config(toml::toml! { + [hostname] + ssh_only = false + trim_at = "" + detect_env_vars = ["FORCE_HOSTNAME"] + }) + .collect(); + let expected = None; + + assert_eq!(expected, actual); + } + + #[test] + fn ssh_only_false_and_in_ssh_connection_with_matching_negated_env() { + let actual = ModuleRenderer::new("hostname") + .config(toml::toml! { + [hostname] + ssh_only = false + trim_at = "" + detect_env_vars = ["SSH_CONNECTION", "!TMUX"] + }) + .env("SSH_CONNECTION", "something") + .env("TMUX", "true") + .collect(); + let expected = None; + + assert_eq!(expected, actual); + } + + #[test] + fn ssh_only_false_without_matching_negated_env() { + let hostname = get_hostname!(); + let actual = ModuleRenderer::new("hostname") + .config(toml::toml! { + [hostname] + ssh_only = false + trim_at = "" + detect_env_vars = ["FORCE_HOSTNAME", "!TMUX"] + }) + .env("FORCE_HOSTNAME", "something") + .collect(); + let expected = Some(format!("{} in ", style().paint(hostname))); + + assert_eq!(expected, actual); + } + + #[test] + fn ssh_only_false_and_in_ssh_connection_without_matching_negated_env() { + let hostname = get_hostname!(); + let actual = ModuleRenderer::new("hostname") + .config(toml::toml! { + [hostname] + ssh_only = false + trim_at = "" + detect_env_vars = ["SSH_CONNECTION", "!TMUX"] + }) + .env("SSH_CONNECTION", "something") + .collect(); + let expected = Some(format!( + "{} in ", + style().paint("🌐 ".to_owned() + hostname.as_str()) + )); + + assert_eq!(expected, actual); + } + #[test] fn ssh_only_false_no_ssh() { let hostname = get_hostname!(); @@ -107,6 +199,7 @@ mod tests { .collect(); let expected = Some(format!("{} in ", style().paint(hostname))); println!("{}", expected.as_ref().unwrap()); + assert_eq!(expected, actual); } @@ -121,6 +214,7 @@ mod tests { }) .collect(); let expected = Some(format!("{} in ", style().paint(hostname))); + assert_eq!(expected, actual); } From 66f0e8d4ea74742d7a0423999d529691bc5d739f Mon Sep 17 00:00:00 2001 From: Mick Hohmann Date: Sun, 21 May 2023 21:54:44 +0200 Subject: [PATCH 2/9] added clippy recommendations, removed unneeded comments --- .github/config-schema.json | 8 ++++++++ src/configs/hostname.rs | 2 +- src/context.rs | 7 ++----- src/modules/hostname.rs | 4 +--- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/.github/config-schema.json b/.github/config-schema.json index 98d6348aedba..19658c6535ef 100644 --- a/.github/config-schema.json +++ b/.github/config-schema.json @@ -784,6 +784,7 @@ }, "hostname": { "default": { + "detect_env_vars": [], "disabled": false, "format": "[$ssh_symbol$hostname]($style) in ", "ssh_only": true, @@ -3699,6 +3700,13 @@ "default": ".", "type": "string" }, + "detect_env_vars": { + "default": [], + "type": "array", + "items": { + "type": "string" + } + }, "format": { "default": "[$ssh_symbol$hostname]($style) in ", "type": "string" diff --git a/src/configs/hostname.rs b/src/configs/hostname.rs index a3c944db539f..879afa3caa02 100644 --- a/src/configs/hostname.rs +++ b/src/configs/hostname.rs @@ -11,7 +11,7 @@ pub struct HostnameConfig<'a> { pub ssh_only: bool, pub ssh_symbol: &'a str, pub trim_at: &'a str, - pub detect_env_vars: Vec<&'a str>, + pub detect_env_vars: Vec<&'a str>, pub format: &'a str, pub style: &'a str, pub disabled: bool, diff --git a/src/context.rs b/src/context.rs index 9b53923f1b8c..f71e48e9c4e3 100644 --- a/src/context.rs +++ b/src/context.rs @@ -237,7 +237,7 @@ impl<'a> Context<'a> { /// Returns true when no negated environment variable is defined in `env_vars` /// or none of the negated variables is set in the environment. - pub fn has_no_negative_env_vars(&self, env_vars: &'a [&'a str]) -> bool { + fn has_no_negative_env_var(&self, env_vars: &'a [&'a str]) -> bool { !env_vars .iter() .any(|env_var| env_var.starts_with('!') && self.get_env(&env_var[1..]).is_some()) @@ -246,12 +246,9 @@ impl<'a> Context<'a> { /// Returns true if 'detect_env_vars' is empty, /// or if at least one environment variable is set and no negated environment variable is set pub fn detect_env_vars(&'a self, env_vars: &'a [&'a str]) -> bool { - // old - // env_vars.is_empty() || (env_vars.iter().any(|e| self.get_env(e).is_some())) - // new env_vars.is_empty() || ((env_vars.iter().any(|e| self.get_env(e).is_some())) - && self.has_no_negative_env_vars(env_vars)) + && self.has_no_negative_env_var(env_vars)) } // returns a new ScanDir struct with reference to current dir_files of context diff --git a/src/modules/hostname.rs b/src/modules/hostname.rs index 1c379fa0acc5..9a5121c1d369 100644 --- a/src/modules/hostname.rs +++ b/src/modules/hostname.rs @@ -17,9 +17,7 @@ pub fn module<'a>(context: &'a Context) -> Option> { let ssh_connection = context.get_env("SSH_CONNECTION"); if config.ssh_only { - if ssh_connection.is_none() { - return None; - } + ssh_connection.as_ref()?; // check for environment variables } else if !(context.detect_env_vars(&config.detect_env_vars)) { return None; From 9ca1f690d4d5168e03931d10d1218e29818318e2 Mon Sep 17 00:00:00 2001 From: Mick Hohmann Date: Sun, 2 Jul 2023 11:54:51 +0200 Subject: [PATCH 3/9] Added new logic (suggested in https://github.com/starship/starship/pull/5196#issuecomment-1566228913) The new `detect_env_vars` now requires either SSH_ONLY to be false or the environment variable SSH_CONNECTION to be set, so that is will be used --- docs/config/README.md | 6 ++--- src/context.rs | 21 ++++++++++----- src/modules/hostname.rs | 60 +++++++++++++---------------------------- 3 files changed, 36 insertions(+), 51 deletions(-) diff --git a/docs/config/README.md b/docs/config/README.md index a718ef675dcc..ca2484611870 100644 --- a/docs/config/README.md +++ b/docs/config/README.md @@ -2202,8 +2202,8 @@ The `hostname` module shows the system hostname. ::: warning -The `detect_env_vars` is only recognized, if `ssh_only` is set to `false`. -You can still check for a ssh connection, add `SSH_CONNECTION` to `detect_env_vars`. +The `detect_env_vars` is only used, if `ssh_only` is set to `false` or there +is an environment variable `SSH_CONNECTION` set. ### Options @@ -2248,7 +2248,7 @@ disabled = false [hostname] ssh_only = false -detect_env_vars = ['!tmux', 'SSH_CONNECTION'] +detect_env_vars = ['!TMUX', 'SSH_CONNECTION'] disabled = false ``` diff --git a/src/context.rs b/src/context.rs index f71e48e9c4e3..ac2c4cfd58b8 100644 --- a/src/context.rs +++ b/src/context.rs @@ -235,20 +235,27 @@ impl<'a> Context<'a> { disabled == Some(true) } - /// Returns true when no negated environment variable is defined in `env_vars` - /// or none of the negated variables is set in the environment. - fn has_no_negative_env_var(&self, env_vars: &'a [&'a str]) -> bool { - !env_vars + /// Returns true when a negated environment variable is defined in `env_vars` and is present + fn has_negated_env_var(&self, env_vars: &'a [&'a str]) -> bool { + env_vars .iter() .any(|env_var| env_var.starts_with('!') && self.get_env(&env_var[1..]).is_some()) } /// Returns true if 'detect_env_vars' is empty, /// or if at least one environment variable is set and no negated environment variable is set + /// or if there are only negated environment variable provided (wich are not set) pub fn detect_env_vars(&'a self, env_vars: &'a [&'a str]) -> bool { - env_vars.is_empty() - || ((env_vars.iter().any(|e| self.get_env(e).is_some())) - && self.has_no_negative_env_var(env_vars)) + if env_vars.is_empty() { + true + } else if self.has_negated_env_var(env_vars) { + false + } else { + env_vars.iter().all(|env_var| env_var.starts_with('!')) + || env_vars + .iter() + .any(|env_var| self.get_env(env_var).is_some()) + } } // returns a new ScanDir struct with reference to current dir_files of context diff --git a/src/modules/hostname.rs b/src/modules/hostname.rs index 9a5121c1d369..40ea37090154 100644 --- a/src/modules/hostname.rs +++ b/src/modules/hostname.rs @@ -16,10 +16,10 @@ pub fn module<'a>(context: &'a Context) -> Option> { let config: HostnameConfig = HostnameConfig::try_load(module.config); let ssh_connection = context.get_env("SSH_CONNECTION"); - if config.ssh_only { - ssh_connection.as_ref()?; - // check for environment variables - } else if !(context.detect_env_vars(&config.detect_env_vars)) { + + if !((!config.ssh_only || ssh_connection.is_some()) + && context.detect_env_vars(&config.detect_env_vars)) + { return None; } @@ -100,16 +100,15 @@ mod tests { } #[test] - fn ssh_only_false_with_matching_env_var() { + fn ssh_only_false_with_empty_detect_env_vars() { let hostname = get_hostname!(); let actual = ModuleRenderer::new("hostname") .config(toml::toml! { [hostname] ssh_only = false trim_at = "" - detect_env_vars = ["FORCE_HOSTNAME"] + detect_env_vars = [] }) - .env("FORCE_HOSTNAME", "true") .collect(); let expected = Some(format!("{} in ", style().paint(hostname))); @@ -117,14 +116,15 @@ mod tests { } #[test] - fn ssh_only_false_without_matching_env_var() { + fn ssh_only_false_with_matching_negated_env_var() { let actual = ModuleRenderer::new("hostname") .config(toml::toml! { [hostname] ssh_only = false trim_at = "" - detect_env_vars = ["FORCE_HOSTNAME"] + detect_env_vars = ["!NEGATED"] }) + .env("NEGATED", "true") .collect(); let expected = None; @@ -132,71 +132,49 @@ mod tests { } #[test] - fn ssh_only_false_and_in_ssh_connection_with_matching_negated_env() { - let actual = ModuleRenderer::new("hostname") - .config(toml::toml! { - [hostname] - ssh_only = false - trim_at = "" - detect_env_vars = ["SSH_CONNECTION", "!TMUX"] - }) - .env("SSH_CONNECTION", "something") - .env("TMUX", "true") - .collect(); - let expected = None; - - assert_eq!(expected, actual); - } - - #[test] - fn ssh_only_false_without_matching_negated_env() { + fn ssh_only_false_with_only_negated_env_vars() { let hostname = get_hostname!(); let actual = ModuleRenderer::new("hostname") .config(toml::toml! { [hostname] ssh_only = false trim_at = "" - detect_env_vars = ["FORCE_HOSTNAME", "!TMUX"] + detect_env_vars = ["!NEGATED_ONE", "!NEGATED_TWO", "!NEGATED_THREE"] }) - .env("FORCE_HOSTNAME", "something") .collect(); - let expected = Some(format!("{} in ", style().paint(hostname))); + let expected = Some(format!("{} in ", style().paint(hostname))); assert_eq!(expected, actual); } #[test] - fn ssh_only_false_and_in_ssh_connection_without_matching_negated_env() { + fn ssh_only_false_with_matching_env_var() { let hostname = get_hostname!(); let actual = ModuleRenderer::new("hostname") .config(toml::toml! { [hostname] ssh_only = false trim_at = "" - detect_env_vars = ["SSH_CONNECTION", "!TMUX"] + detect_env_vars = ["FORCE_HOSTNAME"] }) - .env("SSH_CONNECTION", "something") + .env("FORCE_HOSTNAME", "true") .collect(); - let expected = Some(format!( - "{} in ", - style().paint("🌐 ".to_owned() + hostname.as_str()) - )); + let expected = Some(format!("{} in ", style().paint(hostname))); assert_eq!(expected, actual); } #[test] - fn ssh_only_false_no_ssh() { - let hostname = get_hostname!(); + fn ssh_only_false_without_matching_env_vars() { let actual = ModuleRenderer::new("hostname") .config(toml::toml! { [hostname] ssh_only = false trim_at = "" + detect_env_vars = ["FORCE_HOSTNAME", "!NEGATED"] }) .collect(); - let expected = Some(format!("{} in ", style().paint(hostname))); - println!("{}", expected.as_ref().unwrap()); + let expected = None; assert_eq!(expected, actual); } From 3431c0bde469108d2e18c5e28f22bc0caa5e531c Mon Sep 17 00:00:00 2001 From: Mick Hohmann Date: Sun, 2 Jul 2023 12:05:28 +0200 Subject: [PATCH 4/9] Fixed typo --- src/context.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/context.rs b/src/context.rs index ac2c4cfd58b8..c7b5849e3a38 100644 --- a/src/context.rs +++ b/src/context.rs @@ -244,7 +244,7 @@ impl<'a> Context<'a> { /// Returns true if 'detect_env_vars' is empty, /// or if at least one environment variable is set and no negated environment variable is set - /// or if there are only negated environment variable provided (wich are not set) + /// or if there are only negated environment variable provided (which are not set) pub fn detect_env_vars(&'a self, env_vars: &'a [&'a str]) -> bool { if env_vars.is_empty() { true From e66508b8ee50a3ac266afcc4336392882a1d7869 Mon Sep 17 00:00:00 2001 From: Mick Hohmann Date: Mon, 24 Jul 2023 14:52:45 +0200 Subject: [PATCH 5/9] Refactored the detect_env_vars function for early returns and better readability --- src/context.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/context.rs b/src/context.rs index c7b5849e3a38..010142edd45d 100644 --- a/src/context.rs +++ b/src/context.rs @@ -247,15 +247,19 @@ impl<'a> Context<'a> { /// or if there are only negated environment variable provided (which are not set) pub fn detect_env_vars(&'a self, env_vars: &'a [&'a str]) -> bool { if env_vars.is_empty() { - true - } else if self.has_negated_env_var(env_vars) { - false - } else { - env_vars.iter().all(|env_var| env_var.starts_with('!')) - || env_vars - .iter() - .any(|env_var| self.get_env(env_var).is_some()) + return true; + } + + if self.has_negated_env_var(env_vars) { + return false; } + + // Returns true if all environment variables start with a "!", + // or if at least one environment variable is set + env_vars.iter().all(|env_var| env_var.starts_with('!')) + || env_vars + .iter() + .any(|env_var| self.get_env(env_var).is_some()) } // returns a new ScanDir struct with reference to current dir_files of context From 597845a4e3c73f62ab6025f9577207a92617c770 Mon Sep 17 00:00:00 2001 From: Mick Hohmann Date: Tue, 29 Aug 2023 13:31:27 +0200 Subject: [PATCH 6/9] Change boolean logic for better readability Co-authored-by: David Knaack --- src/modules/hostname.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/hostname.rs b/src/modules/hostname.rs index 40ea37090154..5e637e166b68 100644 --- a/src/modules/hostname.rs +++ b/src/modules/hostname.rs @@ -17,8 +17,8 @@ pub fn module<'a>(context: &'a Context) -> Option> { let ssh_connection = context.get_env("SSH_CONNECTION"); - if !((!config.ssh_only || ssh_connection.is_some()) - && context.detect_env_vars(&config.detect_env_vars)) + if (config.ssh_only && ssh_connection.is_none()) + || !context.detect_env_vars(&config.detect_env_vars)) { return None; } From 18a42251e295937c57d017971dea07108595e717 Mon Sep 17 00:00:00 2001 From: Mick Hohmann Date: Wed, 30 Aug 2023 16:17:13 +0200 Subject: [PATCH 7/9] Apply suggestions from code review to `detect_env_vars` method. Co-authored-by: David Knaack --- src/context.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/context.rs b/src/context.rs index 010142edd45d..f1d39e249b11 100644 --- a/src/context.rs +++ b/src/context.rs @@ -239,7 +239,8 @@ impl<'a> Context<'a> { fn has_negated_env_var(&self, env_vars: &'a [&'a str]) -> bool { env_vars .iter() - .any(|env_var| env_var.starts_with('!') && self.get_env(&env_var[1..]).is_some()) + .filter_map(|env_var| env_var.strip_prefix('!')) + .any(|env_var| self.get_env(env_var).is_some()) } /// Returns true if 'detect_env_vars' is empty, @@ -256,10 +257,12 @@ impl<'a> Context<'a> { // Returns true if all environment variables start with a "!", // or if at least one environment variable is set - env_vars.iter().all(|env_var| env_var.starts_with('!')) - || env_vars - .iter() - .any(|env_var| self.get_env(env_var).is_some()) + let mut iter = env_vars + .iter() + .filter(|env_var| !env_var.starts_with('!')) + .peekable(); + + iter.peek().is_none() || iter.any(|env_var| self.get_env(env_var).is_some()) } // returns a new ScanDir struct with reference to current dir_files of context From 6bccee26636954f74a18f59d286826866004cc21 Mon Sep 17 00:00:00 2001 From: Mick Hohmann Date: Wed, 30 Aug 2023 17:34:44 +0200 Subject: [PATCH 8/9] Fixed bracket error & updated comments - fixed bracket error in hostname.rs, after changes - updated comments for context.rs, for the suggested changes --- src/context.rs | 4 +--- src/modules/hostname.rs | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/context.rs b/src/context.rs index f1d39e249b11..a07530093ed5 100644 --- a/src/context.rs +++ b/src/context.rs @@ -245,7 +245,6 @@ impl<'a> Context<'a> { /// Returns true if 'detect_env_vars' is empty, /// or if at least one environment variable is set and no negated environment variable is set - /// or if there are only negated environment variable provided (which are not set) pub fn detect_env_vars(&'a self, env_vars: &'a [&'a str]) -> bool { if env_vars.is_empty() { return true; @@ -255,8 +254,7 @@ impl<'a> Context<'a> { return false; } - // Returns true if all environment variables start with a "!", - // or if at least one environment variable is set + // Returns true if at least one environment variable is set let mut iter = env_vars .iter() .filter(|env_var| !env_var.starts_with('!')) diff --git a/src/modules/hostname.rs b/src/modules/hostname.rs index 5e637e166b68..8eec9b5ff266 100644 --- a/src/modules/hostname.rs +++ b/src/modules/hostname.rs @@ -18,7 +18,7 @@ pub fn module<'a>(context: &'a Context) -> Option> { let ssh_connection = context.get_env("SSH_CONNECTION"); if (config.ssh_only && ssh_connection.is_none()) - || !context.detect_env_vars(&config.detect_env_vars)) + || !context.detect_env_vars(&config.detect_env_vars) { return None; } From 27901970bee06e539736271889961b0335997312 Mon Sep 17 00:00:00 2001 From: Mick Hohmann Date: Fri, 1 Sep 2023 14:02:22 +0200 Subject: [PATCH 9/9] Removed obsolete warning from docs/config/README.md Co-authored-by: David Knaack --- docs/config/README.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/docs/config/README.md b/docs/config/README.md index ca2484611870..00b596fc0366 100644 --- a/docs/config/README.md +++ b/docs/config/README.md @@ -2200,11 +2200,6 @@ format = 'via [⎈ $version](bold white) ' The `hostname` module shows the system hostname. -::: warning - -The `detect_env_vars` is only used, if `ssh_only` is set to `false` or there -is an environment variable `SSH_CONNECTION` set. - ### Options | Option | Default | Description |