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

opam env adds . to PATH in fish shell #4078

Closed
bbc2 opened this issue Jan 29, 2020 · 3 comments · Fixed by #4084
Closed

opam env adds . to PATH in fish shell #4078

bbc2 opened this issue Jan 29, 2020 · 3 comments · Fixed by #4084
Milestone

Comments

@bbc2
Copy link

bbc2 commented Jan 29, 2020

When I execute eval (opam env), I end up with . in my PATH.

I think the problem is caused by an extra colon in the output of opam env:

set -gx PATH ':/home/bertrand/.opam/4.07.1/bin' '/usr/local/sbin' '/usr/local/bin' '/usr/bin' '/usr/bin/site_perl' '/usr/bin/vendor_perl' '/usr/bin/core_perl';

It results in:

> echo $PATH
. /home/bertrand/.opam/4.07.1/bin /usr/local/sbin /usr/local/bin /usr/bin /usr/bin/site_perl /usr/bin/vendor_perl /usr/bin/core_perl

opam config report

# opam config report
# opam-version      2.0.6 
# self-upgrade      no
# system            arch=x86_64 os=linux os-distribution=arch os-version=unknown
# solver            builtin-mccs+glpk
# install-criteria  -removed,-count[version-lag,request],-count[version-lag,changed],-changed
# upgrade-criteria  -removed,-count[version-lag,solution],-new
# jobs              7
# repositories      1 (http), 1 (version-controlled) (default repo at 203e326c)
# pinned            1 (git), 1 (rsync)
# current-switch    4.07.1
@rjbou
Copy link
Collaborator

rjbou commented Jan 30, 2020

It comes from #3878: for MANPATH that leading ':' is needed (#3878). Seems that should be restrained only to MANPATH, and not added for PATH & CDPATH as they are completely redefined.

@rjbou
Copy link
Collaborator

rjbou commented Feb 20, 2020

Thanks for the report!

@rjbou rjbou added this to the 2.1.0 milestone Feb 25, 2020
@undu
Copy link

undu commented Sep 2, 2020

I've encountered this issue since I prefer per-session switches so I though sharing my workaround to whoever finds this thread.

I use a function to wrap switch activation (in $XDG_CONFIG_HOME/fish/functions/oswitch.fish):

function oswitch
    if test (count $argv) -lt 1
        echo "oswitch: expected a least an arg, got none"
        echo "Usage: oswitch <switch>"
        return -1
    end
    set switch "$argv[1]"
    if opam switch set --dry-run "$switch" 2> /dev/null > /dev/null
        eval (opam env --switch="$switch" --set-switch)
        # opam adds . to PATH, delete it if it's present
        if set -l i (contains -i -- '.' $PATH)
                set -e PATH[$i]
        end
    else
        # show output
        opam switch set --dry-run "$switch"
    end
end

The recommended way to add paths to fish is to append paths to $fish_user_paths instead of directly setting the $PATH, but I don't know how well that meshes with cross-shell handling in opam. Adding a path would be usually done with contains $path $fish_user_paths; or set -a fish_user_paths $path

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants