Skip to content
Snippets Groups Projects

Avoid adding duplicates to PATH

Merged Rufflewind requested to merge Rufflewind/ghcup-hs:Rufflewind-master-patch-04223 into master
1 unresolved thread

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

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
280 280
281 281 # we may overwrite this in adjust_bashrc
282 282 cat <<-EOF > "${GHCUP_DIR}"/env || die "Failed to create env file"
    1. this file may be overwritten in the adjust_bashrc function, as the comment indicates
    2. for fish shell, this file isn't used
    3. is this even the right place to do the conditional?
  • Author Contributor
    1. I have updated other occurrences. Please let me know if there's any others I missed.
    2. Sorry, I am not familiar with fish so I don't think I would know how to make changes in that area.
    3. 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.
    1. 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 if GHCUP_BIN diverges maybe.

    Also... this patch will change the following situation:

    1. user has manually added $HOME/.ghcup/bin to PATH (somewhere in the middle of it)
    2. something doesn't work, because ghc is shadowed
    3. 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 Ospald
  • Author Contributor

    So, 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?

  • nah... I guess it's simpler to keep it in env file then

    I also noticed all whitespaces are stripped, which makes the file hard to read, so we'll have to adjust the cat/EOF thing.

  • Author Contributor

    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
  • Please register or sign in to reply
  • Rufflewind added 1 commit

    added 1 commit

    • 3565c32d - Avoid adding duplicates to PATH

    Compare with previous version

  • merged

  • mentioned in merge request Rufflewind/ghcup-hs!1 (closed)

  • Rufflewind mentioned in merge request !232 (merged)

    mentioned in merge request !232 (merged)

  • Please register or sign in to reply
    Loading