Skip to content
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

hide and hide-env sometimes doesn't hide env vars #6593

Closed
fdncred opened this issue Sep 20, 2022 · 7 comments
Closed

hide and hide-env sometimes doesn't hide env vars #6593

fdncred opened this issue Sep 20, 2022 · 7 comments
Labels
🐛 bug Something isn't working scoping/name-resolution How Nu finds which variables/functions are in scope and to what they are bound

Comments

@fdncred
Copy link
Collaborator

fdncred commented Sep 20, 2022

Describe the bug

Sometimes hide and hide-env won't hide environment variables. It seems to work fine on Windows but I can't get it to work on WSL/Ubuntu.

How to reproduce

  1. Create this alias in your config.nu alias lsg = (ls | sort-by type name -i | grid -c)
  2. Also in your config.nu create this hook.
hooks: {
  ...
  env_change: {
    PWD: [{|before, after|
      print (lsg)
    }]
  }
}
  1. The very last line in your config.nu should be hide LS_COLORS or hide-env LS_COLORS. I do this so that there is no possibility of a parent shell having a LS_COLORS env var and nushell inheriting it.

Expected behavior

Based on the example above, every time you change directory you should get a lsg output with the default nushell LS_COLORS. What's happening is there is some LS_COLORS being inherited in WSL and therefore the colors are wrong.

Screenshots

No response

Configuration

key value
version 0.68.2
branch main
commit_hash 0b9dd87
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.61.0 (fe5b13d68 2022-05-18)
rust_channel 1.61.0-x86_64-unknown-linux-gnu
cargo_version cargo 1.61.0 (a028ae4 2022-04-29)
pkg_version 0.68.2
build_time 2022-09-19 12:58:25 -05:00
build_rust_channel release
features database, dataframe, default, trash, which, zip
installed_plugins custom-value generate, custom-value generate2, custom-value update, from parquet, gstat, inc, nu-example-1, nu-example-2, nu-example-3, query, query json, query web, query xml

Additional context

This seems to only happen when you have a parent shell. Also of note is that if you just type lsg in the repl, the colors are correct. So, in the repl, the hide is working. It's just not working right in the hook.

@fdncred fdncred added the 🐛 bug Something isn't working label Sep 20, 2022
@gotounix
Copy link

gotounix commented Sep 21, 2022

It's not woking on Windows.

starship/starship#4386

@kubouch
Copy link
Contributor

kubouch commented Sep 21, 2022

@gotounix Just FYI, once this PR lands pypa/virtualenv#2422 the virtualenv activation script will use the overlay system to activate the environment variables, so the hide or hide-env keywords won't be used anymore.

This hide-env stuff still need to be fixed.

@Decodetalkers Decodetalkers mentioned this issue Nov 4, 2022
7 tasks
@Decodetalkers
Copy link
Contributor

Decodetalkers commented Nov 4, 2022

image
I don't think it is the bug of "hide-env", the bug maybe come from the hook

@Decodetalkers
Copy link
Contributor

Decodetalkers commented Nov 4, 2022

You can repreduced it with

let-env a = 10
hide-env a
let c = {
$env.a
}
do $c

Then you will get 10
However you cannot echo $env.a , but you can get the value in a block
and then

let-env a = 11
do $c

then you can get 11
Seems the variables are still alive in blocks

This picture is more interesting
image

Seems eveything when come into the block , the variable will still exist

@github-actions github-actions bot added the Stale used for marking issues and prs as stale label Feb 3, 2023
@refl3ction
Copy link

refl3ction commented Feb 9, 2023

I also noticed this behavior and reported it here. I'm using nushell on MacOS. Any update?

@github-actions github-actions bot removed the Stale used for marking issues and prs as stale label Feb 10, 2023
kubouch added a commit that referenced this issue Feb 12, 2023
# Description

This one fixes env not being hidden inside closure, reported in the
conversation under #6593

#6593
#7937 still persist. These
seems a bit more involved and might need hidden env tracking also in the
engine state... I'm not yet sure what's causing it.

Also re-enables some env-related tests and removes unused Value clone.

# User-Facing Changes

Just a bugfix

# Tests + Formatting

Don't forget to add tests that cover your changes.

Make sure you've run and fixed any issues with these commands:

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
@fdncred
Copy link
Collaborator Author

fdncred commented Sep 26, 2023

related to #7937

@sholderbach sholderbach added the scoping/name-resolution How Nu finds which variables/functions are in scope and to what they are bound label Sep 26, 2023
@fdncred
Copy link
Collaborator Author

fdncred commented Sep 26, 2023

I've investigated more and it seems like this one more closely related to #7937 than I thought, since, for me, I'd have to have this env var set in a parent shell to repro this problem. I'm closing it. If anyone still has these issues, ping me and I'll reopen it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working scoping/name-resolution How Nu finds which variables/functions are in scope and to what they are bound
Projects
None yet
Development

No branches or pull requests

6 participants