Avoid adding duplicates to PATH
Without this, each time the env script gets executed it will add a copy of the paths to PATH. This can happen when shells are nested.
The "case" trick was inspired by: https://github.com/rust-lang/rustup/blob/184a899f4529f27e23eca537a5979c530ff7fa26/src/cli/self_update/env.sh
Merge request reports
Activity
280 280 281 281 # we may overwrite this in adjust_bashrc 282 282 cat <<-EOF > "${GHCUP_DIR}"/env || die "Failed to create env file" - I have updated other occurrences. Please let me know if there's any others I missed.
- Sorry, I am not familiar with fish so I don't think I would know how to make changes in that area.
- Where do you suggest putting the conditional? Keep in mind the check has to be done at run time since the goal is to prevent repeated occurrences caused by recursion.
- Where do you suggest putting the conditional? Keep in mind the check has to be done at run time since the goal is to prevent repeated occurrences caused by recursion.
Where the env file is sourced: in
.bashrc
? Although that opens up the possibility of a false check ifGHCUP_BIN
diverges maybe.Also... this patch will change the following situation:
- user has manually added $HOME/.ghcup/bin to PATH (somewhere in the middle of it)
- something doesn't work, because
ghc
is shadowed - user runs
source ~/.ghcup/env
to ensure ghcup bin path is prepended (but now it won't, because of the case-switch)
Not sure this is really what people expect, but...
Edited by Julian OspaldSo, if there is an absolute need to have
~/.ghcup/env
usable both (a) on demand and (b) also passively through the rc file, then one could introduce another script, say~/.ghcup/env-init
, which invokes~/.ghcup/env
with conditional guards to ensure idempotency. Then,~/.bashrc
can call~/.ghcup/env-init
.This would hide the complexity from the user's
~/.bashrc
and avoid clutter. What do you think?I also noticed all whitespaces are stripped, which makes the file hard to read, so we'll have to adjust the cat/EOF thing.
I changed the indentation within the heredoc to four spaces: !232 (merged)
Anything else needed?
Edited by Rufflewind
mentioned in merge request Rufflewind/ghcup-hs!1 (closed)
mentioned in merge request !232 (merged)