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
feat(hostname): add detect_env_vars as option #5196
feat(hostname): add detect_env_vars as option #5196
Conversation
src/context.rs
Outdated
env_vars.is_empty() | ||
|| ((env_vars.iter().any(|e| self.get_env(e).is_some())) | ||
&& self.has_no_negative_env_var(env_vars)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of env_vars.is_empty()
it might be better to use env_vars.any(|e| !e.starts_with('!'))
to better support negative-only matchers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of the supposed formula in #5196 (comment) we decided to leave it in.
docs/config/README.md
Outdated
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`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes more sense to join both with AND
(or OR
?) conditions.
If we decide to keep this behavior, it would warrant a log::warn!
in the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is one combination, I'm unsure how to handle: what happens if an environment variable is configured for detect_env_vars
and it is not set in the shell environment?
With ssh_only = "false"
, my logic would say: hide the hostname. With ssh_only = "true"
and an active ssh
connection, what should take precedence: the ssh_only
or the detect_env_vars
option?
See my comment for a new truth table.
As, I prefer to have it documented here, below is a new truth table for David's review comment: Truth table for combining
|
ssh_only | SSH_CONNECTION | detect_env_vars | result |
---|---|---|---|
true | true | empty | show hostname (like now) |
true | true | positive | show hostname |
true | true | none | ❓ hostname |
true | true | negative | hide❗ hostname |
true | false | empty | hide hostname (like now) |
true | false | positive | show❗ hostname |
true | false | none | ❓ hostname |
true | false | negative | hide hostname |
false | true | empty | show hostname (like now) |
false | true | positive | show hostname |
false | true | none | hide hostname |
false | true | negative | hide hostname |
false | false | empty | show hostname (like now) |
false | false | positive | show hostname |
false | false | none | hide hostname |
false | false | negative | hide hostname |
I'm unsure how to handle the two conditions, marked with ❓, in the above table.
I think it makes the most sense to consider both options mutually independent boolean variables. In that case, I think it makes the most sense to enable the module if |
I believe the definition of Regarding the cases of |
The only part ("matchers") is concerned with the matchers themselves, so having only The other one ("matches") is concerned with the evaluated matcher-matches. |
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
1375f68
to
2e58a5a
Compare
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
8da0d9e
to
53a149b
Compare
Additionally, to the test on macOS, I did test the new feature on NixOS as well. |
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
90613d6
to
949661d
Compare
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 <dsander@users.noreply.github.com>
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
Co-authored-by: David Knaack <davidkna@users.noreply.github.com>
Co-authored-by: David Knaack <davidkna@users.noreply.github.com>
08265a1
to
18a4225
Compare
- fixed bracket error in hostname.rs, after changes - updated comments for context.rs, for the suggested changes
Co-authored-by: David Knaack <davidkna@users.noreply.github.com>
Thanks for the contribution @mickimnet! |
Thank you so much, for your support @davidkna |
Hello everybody,
Motivation and Context
I don't use the default
hostname
module and instead use a custom module because I frequently use terminal multiplexers liketmux
,screen
, orZellji
. These multiplexers display the hostname in the status bar, so I don't want or need to see it in the terminal as well.Description
To achieve this, I added the
context::detect_env_vars
function to thehostname
module and also added a newcontext::has_no_negative_env_vars
function to it.This is the first time I've written anything other than shell scripts, so please bear with me🫣 I couldn't have done it without the invaluable help of my friend and experienced Rustacean, @dsander 💛
Option combinations
I created a truth table to outline the expected behavior of the changes:
Legend:
detect_env_vars
:positive
: a name of an environment variable is configured and the variable is setempty
: the array is emptydetect_env_vars = none:
none of the entered environment variables are setdetect_env_vars = negative
: the name of an environment variable is prefixed with an "!" and the variable is setHint: If
ssh_only
is set tofalse
and you still want to see thehostname
in anssh
connection, you will need to addSSH_CONNECTION
to thedetect_env_vars
array. My use case can be achieved with the following configuration:How Has This Been Tested?
Checklist:
Thank you and have fun!
Mick
Edith says: exchanged the truth table with an actual table 😄