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 init breaks fish shell with configuration #2255

Closed
dongcarl opened this issue Jul 13, 2015 · 34 comments
Closed

opam init breaks fish shell with configuration #2255

dongcarl opened this issue Jul 13, 2015 · 34 comments

Comments

@dongcarl
Copy link

Tested on Ubuntu, Mac OS X, and FreeBSD.

When I invoke opam init, this is inserted in my config.fish

. /home/dongcarl/.opam/opam-init/init.fish > /dev/null 2> /dev/null or true

I'm not sure exactly how but this line renders the fish shell completely unusable. I have resorted to replacing the aforementioned line with eval (opam config env)

@AltGr
Copy link
Member

AltGr commented Jul 17, 2015

Can you give the precise opam version ? (opam config report)

The output of manually running . /home/dongcarl/.opam/opam-init/init.fish could help.

Thanks for reporting!

@dongcarl
Copy link
Author

Here's the config report

# OPAM config report
# opam-version    1.2.2 
# self-upgrade    no
# os              darwin
# external-solver aspcud $in $out $criteria
# criteria        -count(removed),-notuptodate(request),-sum(request,version-lag),-count(down),-notuptodate(changed),-count(changed),-notuptodate(solution),-sum(solution,version-lag)
# jobs            4
# repositories    1* (http), 1 (version-controlled)
# pinned          0
# current-switch  system*
# last-update     2015-07-11 14:29

I've talked to people on the mailing list about this and come up with a fix thanks to Zanchey on fish shell IRC.

The proper configuration would have the following files:

config.fish

# OPAM configuration
. /Users/dongcarl/.opam/opam-init/init.fish > /dev/null 2> /dev/null; or true

init.fish

# Load the environment variables
. /Users/dongcarl/.opam/opam-init/variables.fish > /dev/null 2> /dev/null; or true

The above two files have a semicolon before the "or true"

variables.fish

set -gx PATH "/Users/dongcarl/.opam/system/bin" $PATH;
set -gx OCAML_TOPLEVEL_PATH "/Users/dongcarl/.opam/system/lib/toplevel";
set -gx PERL5LIB "/Users/dongcarl/.opam/system/lib/perl5:$PERL5LIB";
set -gx MANPATH $MANPATH "/Users/dongcarl/.opam/system/man";
set -gx OPAMUTF8MSGS "1";
set -gx CAML_LD_LIBRARY_PATH "/Users/dongcarl/.opam/system/lib/stublibs:/usr/local/lib/ocaml/stublibs";

The above file doesn't have double quotes around the $PATH and the $MANPATH

I've been looking at the repository and couldn't figure out which files to change... opamState looks like the place to fix things in variables.fish but it says (* PATH is always set *). Help would be greatly appreciated!

@berdario
Copy link

I have the same problem

This seems to be issue #2244 , which has already been fixed

When can we expect 1.2.3 to be released with this fix?

@raichoo
Copy link

raichoo commented Oct 20, 2015

Same issue here.

@jeremy-w
Copy link

I ran into this as well. Based on the error messages I was getting, I could tell that PATH had gotten bungled. It ends up looking like:

PATH=/Users/jeremy/.opam/system/bin:/Users/jeremy/.pyenv/shims /Users/jeremy/.rbenv/shims …

So two items, the .opam bin and then a totally collection of space-separated paths, which don't work for executable lookup.

I commented out the OPAM config line in my fish.config for now as a workaround.

@dongcarl
Copy link
Author

I just installed Arch Linux and wanted to try opam, and this still happens.

@macleginn
Copy link

I just installed opam under OS X, and fish got broken as reported above. Manually adding two semicolons in config.fish and init.fish and removing redundant quotes from variables.fish brought it back to life.

@talex5
Copy link

talex5 commented Jan 6, 2016

Just hit the same problem (on OS X). For anyone else searching on the error message, this is the output you see after starting a new shell:

Last login: Wed Jan  6 14:41:05 on ttys006
fish: Unknown command 'uname'
/usr/local/Cellar/fish/2.2.0/share/fish/functions/__fish_pwd.fish (line 1): uname
                                    ^
in command substitution
    called on line -1 of file /usr/local/Cellar/fish/2.2.0/share/fish/functions/__fish_pwd.fish

from sourcing file /usr/local/Cellar/fish/2.2.0/share/fish/functions/__fish_pwd.fish
    called on standard input

in command substitution
    called on standard input

in command substitution
    called on standard input

switch: Expected exactly one argument, got 0

/usr/local/Cellar/fish/2.2.0/share/fish/functions/__fish_pwd.fish (line 1): switch (uname)
                                           ^
from sourcing file /usr/local/Cellar/fish/2.2.0/share/fish/functions/__fish_pwd.fish
    called on standard input

in command substitution
    called on standard input

in command substitution
    called on standard input

fish: Unknown command '__fish_pwd'
fish: echo $_ " "; __fish_pwd
           ^
in command substitution
    called on standard input

Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish
/usr/local/Cellar/fish/2.2.0/share/fish/functions/type.fish (line 1): seq (count $argv)
                                  ^
in command substitution
    called on line 2 of file /usr/local/Cellar/fish/2.2.0/share/fish/functions/type.fish

in function 'type'
    called on standard input
    with parameter list '-q -p command-not-found'

in function '__fish_command_not_found_setup'
    called on line 6 of file /usr/local/Cellar/fish/2.2.0/share/fish/functions/fish_prompt.fish
    with parameter list 'hostname'

in event handler: handler for generic event 'fish_command_not_found'

/usr/local/Cellar/fish/2.2.0/share/fish/functions/type.fish (line 1): seq (count $argv)
                                  ^
in command substitution
    called on line 2 of file /usr/local/Cellar/fish/2.2.0/share/fish/functions/type.fish

in function 'type'
    called on standard input
    with parameter list '-p -q pkgfile'

in function '__fish_command_not_found_setup'
    called on line 6 of file /usr/local/Cellar/fish/2.2.0/share/fish/functions/fish_prompt.fish
    with parameter list 'hostname'

in event handler: handler for generic event 'fish_command_not_found'

fish: Unknown command 'hostname'
/usr/local/Cellar/fish/2.2.0/share/fish/functions/fish_prompt.fish (line 1): hostname|cut -d . -f 1
                                     ^
in command substitution
    called on line 4 of file /usr/local/Cellar/fish/2.2.0/share/fish/functions/fish_prompt.fish

in function 'fish_prompt'
    called on standard input

in command substitution
    called on standard input

fish: Unknown command 'uname'
/usr/local/Cellar/fish/2.2.0/share/fish/functions/prompt_pwd.fish (line 1): uname
                                    ^
in command substitution
    called on line -1 of file /usr/local/Cellar/fish/2.2.0/share/fish/functions/prompt_pwd.fish

from sourcing file /usr/local/Cellar/fish/2.2.0/share/fish/functions/prompt_pwd.fish
    called on line 6 of file /usr/local/Cellar/fish/2.2.0/share/fish/functions/fish_prompt.fish

in command substitution
    called on line 4 of file /usr/local/Cellar/fish/2.2.0/share/fish/functions/fish_prompt.fish

in command substitution
    called on line 4 of file /usr/local/Cellar/fish/2.2.0/share/fish/functions/fish_prompt.fish

in function 'fish_prompt'
    called on standard input

in command substitution
    called on standard input

switch: Expected exactly one argument, got 0

/usr/local/Cellar/fish/2.2.0/share/fish/functions/prompt_pwd.fish (line 3): switch (uname)
                                           ^
from sourcing file /usr/local/Cellar/fish/2.2.0/share/fish/functions/prompt_pwd.fish
    called on line 6 of file /usr/local/Cellar/fish/2.2.0/share/fish/functions/fish_prompt.fish

in command substitution
    called on line 4 of file /usr/local/Cellar/fish/2.2.0/share/fish/functions/fish_prompt.fish

in command substitution
    called on line 4 of file /usr/local/Cellar/fish/2.2.0/share/fish/functions/fish_prompt.fish

in function 'fish_prompt'
    called on standard input

in command substitution
    called on standard input

fish: Unknown command 'sed'
/usr/local/Cellar/fish/2.2.0/share/fish/functions/prompt_pwd.fish (line 2):     echo $PWD | sed -e "s|^$realhome|~|" $args_pre -e 's-\([^/.]\)[^/]*/-\1/-g' $args_post
                                            ^
in function 'prompt_pwd'
    called on line 6 of file /usr/local/Cellar/fish/2.2.0/share/fish/functions/fish_prompt.fish

in command substitution
    called on line 4 of file /usr/local/Cellar/fish/2.2.0/share/fish/functions/fish_prompt.fish

in function 'fish_prompt'
    called on standard input

in command substitution
    called on standard input

fish: Unknown command '__fish_pwd'
fish: echo $_ " "; __fish_pwd
           ^
in command substitution
    called on standard input

tal@ > 

@robo-corg
Copy link

I fixed this on my osx install by changing the line where the path is set to be:

set PATH "/Users/amcharg/.opam/system/bin" $PATH;

Based on the advice in this comment: fish-shell/fish-shell#527 (comment) for setting paths in fish. My guess is the way it is being set here by opam is incorrect? Not much of a fish expert yet but it the spew of errors seems to indicate its clobbering path.

roryokane added a commit to roryokane/opam that referenced this issue Jan 29, 2016
In Fish, `or` is a command of its own, not a syntax element. So you need a semicolon before it to start a new command. Reference: http://fishshell.com/docs/current/commands.html#or

This should be the last fix needed to solve ocaml#2255 – the other issues were fixed by 758c391 (use `source`) and c87a280 (don’t quote array variables).
@roryokane
Copy link
Contributor

Between my pull request #2424 and the earlier pull request #2169, we now have all the fixes to solve this issue. We just need to wait for a release of OPAM that contains those fixes.

Until then, here are instructions for manually fixing your files:

~/.config/fish/config.fish

Replace . with source and add a semicolon before or:

 # OPAM configuration
-. /Users/you/.opam/opam-init/init.fish > /dev/null 2> /dev/null or true
+source /Users/you/.opam/opam-init/init.fish > /dev/null 2> /dev/null; or true

~/.opam/opam-init/init.fish

Replace . with source and add a semicolon before or:

 # Load the environment variables
-. /Users/you/.opam/opam-init/variables.fish > /dev/null 2> /dev/null or true
+source /Users/you/.opam/opam-init/variables.fish > /dev/null 2> /dev/null; or true

~/.opam/opam-init/variables.fish

Unquote $PATH and $MANPATH:

-set -gx PATH "/Users/you/.opam/system/bin" "$PATH";
+set -gx PATH "/Users/you/.opam/system/bin" $PATH;
 set -gx OCAML_TOPLEVEL_PATH "/Users/you/.opam/system/lib/toplevel";
 set -gx PERL5LIB "/Users/you/.opam/system/lib/perl5:$PERL5LIB";
-set -gx MANPATH "$MANPATH" "/Users/you/.opam/system/man";
+set -gx MANPATH $MANPATH "/Users/you/.opam/system/man";
 set -gx OPAMUTF8MSGS "1";
 set -gx CAML_LD_LIBRARY_PATH "/Users/you/.opam/system/lib/stublibs:/usr/local/lib/ocaml/stublibs";

Optionally, if you want the file to look neater, you can also remove the ending semicolons ;. The semicolons are redundant, but shouldn’t harm anything.

@avegancafe
Copy link

Thought I should let people know, I'm still getting this error. The fix posted here is awesome, thanks @roryokane. However, it's probably annoying if one manages to miss this. I installed opam via homebrew, was this change not implemented there as well?

@tathanhdinh
Copy link

Thanks @roryokane , your fix works for me also.

@martinklepsch
Copy link

Also installed opam via homebrew and was initially amazed by the fact that there was special guidance for fish users. Then ran into this as well :) Would be great to have this fixed by default. 👍

@talex5
Copy link

talex5 commented Apr 26, 2016

Note: this doesn't just affect init. My shell config is broken every time I do opam switch too.

@johshoff
Copy link

As suggested in #2169, I'd like to encourage making a point release with these two fixes. Current behavior breaks the configuration of fish shells when installing the latest release, 1.2.2 (released a year ago, so I'm assuming this is what most package managers have).

@tchajed
Copy link
Contributor

tchajed commented Aug 17, 2016

@AltGr: could you please release a new 1.2.3 version of opam with these fixes? df51212 adds 75 more commits over 1.2.2 and fixes the most pressing concern (opam init breaking the shell) for Fish users.

@ariasuni
Copy link

ariasuni commented Sep 19, 2016

I lost half an hour to find this bug report, so it would be nice to have this to work: many users may not have the luck or the patience to find it.

@mfaerevaag
Copy link

mfaerevaag commented May 12, 2017

Almost a year later and this is still a problem in 1.2.2, which is the one found in the pacman repo (Arch Linux package manager). Not sure who is admin of the package (can't bother to check), but could be nice if it was updated..

@sharno
Copy link

sharno commented Oct 4, 2017

When is opam 1.2.3 going to be released? I'm on MacOS and still this error is present almost 2 years after the issue appeared.

@cartazio
Copy link

I'm still hitting this issue :(

@avegancafe
Copy link

Who in the world is responsible for deploying this project to homebrew? I wanna know who to ping lol

@sharno
Copy link

sharno commented Jan 25, 2018

If you're still hitting this issue, I'd suggest to try opam 2.0 beta, it'll definitely fix the issue and seems stable to me

@dogweather
Copy link

dogweather commented Aug 30, 2018

Still an issue on OSX with Homebrew which provides 1.2.2. Workaround is removing the quotes around $PATH. According to brew info opam, this is the source for it:

https://github.com/Homebrew/homebrew-core/blob/master/Formula/opam.rb

Maybe one of the contributors there would be down for making a 1.2.3 recipe.

FYI, this isn't a problem, though, on Fedora, which installed/upgraded itself to 2.0.0~beta6.

@avegancafe
Copy link

I'm curious why this was closed if it wasn't fully published 🤔 ++ on publishing this to homebrew, it's the primary package manager for macs

@rjbou
Copy link
Collaborator

rjbou commented Sep 4, 2018

It was closed because the issue has been fixed on master at the time (PR #2424).
opam 2.0.0 will be released in few days (cf. rc4 and roadmap posts), but as we don't maintain OS packages ourselves, we contacted OS maintainers to let them know about the roadmap.
Until it is released, you can upgrade your installed opam as explained in the rc4 blog post.

@avegancafe
Copy link

Is there anywhere we could follow up on that conversation? I assumed this repo's maintainers were responsible for publishing it, since they own the actual product @rjbou

@avegancafe
Copy link

(also thanks for looping them in!)

@avsm
Copy link
Member

avsm commented Sep 8, 2018

For now, a workaround is to use our brew tap with opam2: brew install ocaml/ocaml/opam@2

@tchajed
Copy link
Contributor

tchajed commented Sep 24, 2018

For the record, with the release of opam 2.0.0 this issue has finally been fixed - thanks @rjbou!

@johshoff
Copy link

And to add to that, 2.0.0 is now available with brew install opam or brew upgrade opam. No need for the special brew tap anymore.

@dan-f
Copy link

dan-f commented Oct 12, 2018

I still have this problem on the latest fish/opam:

~ $ fish --version
fish, version 2.7.1
~ $ opam --version
2.0.0

edit -- it looks like upgrading opam through homebrew did not update the scripts in the .opam directory. This feels like a bug, but perhaps a separate one...

@rjbou
Copy link
Collaborator

rjbou commented Oct 12, 2018

Scripts in the opam root are installed only in the init step. To update them, run an opam init --reinit -ni. It is specified in blog posts, but worth adding in the main doc.

@evanhackett
Copy link

evanhackett commented Nov 21, 2019

I recently installed opam while using fish, and it did still have 1 problem: it broke my man command by setting $MANPATH, so now my man command can't find anything except ocaml related things.

I installed opam 2.0.5
I have fish 3.0.2

I fixed it by changing the line that sets MANPATH to this:

set -q MANPATH || set MANPATH ''
set -gx MANPATH $MANPATH /home/evan/.opam/4.07.1/man

This fix made it so man can continue to find system commands like ls, cd, etc. instead of only ocaml related things.

@rjbou
Copy link
Collaborator

rjbou commented Nov 21, 2019

In #3886, we added the semi colon that permit appending MANPATH (cf. #3878). Can you confirm that it resolves your problem ?
We can integrate this fix in the next 2.0.6 release.

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

No branches or pull requests