Allow set --query to check for pathvarness (#8494)

Currently,

    set -q --unpath PATH

simply ignores the "--unpath" bit (and same for "--path").

This changes it, so just like exportedness you can check pathness.
This commit is contained in:
Fabian Homborg
2021-11-26 18:29:10 +01:00
committed by GitHub
parent 41be9fa9fd
commit 47e45704b1
4 changed files with 34 additions and 1 deletions

View File

@@ -509,6 +509,14 @@ struct query_t {
return true;
}
}
bool pathvar_matches(const env_var_t &var) const {
if (has_pathvar_unpathvar) {
return var.is_pathvar() ? pathvar : unpathvar;
} else {
return true;
}
}
};
// Struct representing one level in the function variable stack.
@@ -804,6 +812,10 @@ maybe_t<env_var_t> env_scoped_impl_t::get(const wcstring &key, env_mode_flags_t
if (result && !query.export_matches(*result)) {
result = none();
}
// Same for pathvars
if (result && !query.pathvar_matches(*result)) {
result = none();
}
return result;
}