From 43b2d42cd526e34c5f0290e7409fbd6d3a54e908 Mon Sep 17 00:00:00 2001 From: Mick Hohmann Date: Sat, 16 Sep 2023 16:42:13 +0200 Subject: feat(hostname): add detect_env_vars as option (#5196) * 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 * added clippy recommendations, removed unneeded comments * 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 * Fixed typo * Refactored the detect_env_vars function for early returns and better readability * Change boolean logic for better readability Co-authored-by: David Knaack * Apply suggestions from code review to `detect_env_vars` method. Co-authored-by: David Knaack * Fixed bracket error & updated comments - fixed bracket error in hostname.rs, after changes - updated comments for context.rs, for the suggested changes * Removed obsolete warning from docs/config/README.md Co-authored-by: David Knaack --------- Co-authored-by: Dominik Sander Co-authored-by: David Knaack --- docs/config/README.md | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'docs/config/README.md') diff --git a/docs/config/README.md b/docs/config/README.md index 2b171535b..ac116b9d6 100644 --- a/docs/config/README.md +++ b/docs/config/README.md @@ -2238,14 +2238,15 @@ The `hostname` module shows the system hostname. ### 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 @@ -2257,7 +2258,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 @@ -2269,6 +2272,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/). -- cgit v1.2.3