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

[Suggestion] Have sandboxed terminals alias opam to opam --switch=$SWITCH #655

Closed
yannl35133 opened this issue Jul 5, 2021 · 8 comments · Fixed by #744
Closed

[Suggestion] Have sandboxed terminals alias opam to opam --switch=$SWITCH #655

yannl35133 opened this issue Jul 5, 2021 · 8 comments · Fixed by #744
Labels
good first issue Good for newcomers type: bug Something isn't working

Comments

@yannl35133
Copy link
Contributor

I find myself quite often using opam from within the sandboxed terminal, forgetting that I am modifying the wrong switch.

Is it feasible to have sandboxed terminals alias opam to opam --switch=$SWITCH ?
This may need to be opt-in, considering that changing the switch from within wouldn't remove the option.

@ulugbekna
Copy link
Collaborator

ulugbekna commented Jul 5, 2021 via email

@yannl35133
Copy link
Contributor Author

OCaml: Create terminal (current sandbox) only sets the correct environment (as in eval $(opam env) I think)
It definitely doesn't change the switch affected by commands like opam install

@ulugbekna
Copy link
Collaborator

ulugbekna commented Jul 5, 2021 via email

@yannl35133
Copy link
Contributor Author

$ opam install dedukti
[NOTE] Package dedukti is already installed (current version is 2.6.0).
$ opam install dedukti --switch=logipedia

<><> Synchronising pinned packages ><><><><><><><><><><><><><><><><><><><><><><>
[dedukti.devel] synchronised (no changes)

[NOTE] Package dedukti is already installed (current version is devel).
$ opam exec --switch=logipedia -- opam install dedukti
[NOTE] Package dedukti is already installed (current version is 2.6.0).

This may be a bug in opam directly (I'm on ~rc2)

@ulugbekna
Copy link
Collaborator

ulugbekna commented Jul 5, 2021

I think we have a bug in the extension: we should also be setting the --set-switch flag perhaps. (I have opam 2.0.8)

--set-switch
With the env and exec subcommands, also sets the OPAMSWITCH
variable, making sure further calls to opam will use the same
switch as this one.

╭─ ~/code/try-ocaml 
╰─❯ opam switch
#  switch                           compiler                    description
→  /Users/ulugbekna/code/try-ocaml  ocaml-base-compiler.4.12.0  /Users/ulugbekna/code/try-ocaml
   4.12.0                           ocaml-base-compiler.4.12.0  4.12.0

[NOTE] Current switch has been selected based on the current directory.
       The current global system switch is 4.12.0.

╭─ ~/code/try-ocaml 
╰─❯ opam exec --switch=4.12.0 --set-switch -- zsh

╭─ ~/code/try-ocaml 
╰─❯ opam switch
#  switch                           compiler                    description
   /Users/ulugbekna/code/try-ocaml  ocaml-base-compiler.4.12.0  /Users/ulugbekna/code/try-ocaml
→  4.12.0                           ocaml-base-compiler.4.12.0  4.12.0

[NOTE] Current switch is set globally and through the OPAMSWITCH variable.
       Thus, the local switch found at /Users/ulugbekna/code/try-ocaml was ignored.

cc @tmattio @mnxn

@mnxn
Copy link
Collaborator

mnxn commented Jul 5, 2021

we should also be setting the --set-switch flag perhaps.

Yes, this looks like the correct solution. The flag is available in opam 2.0.7 on Windows too, so it should be fine to just modify the command.

@tmattio tmattio added type: bug Something isn't working good first issue Good for newcomers labels Oct 5, 2021
@SaySayo
Copy link
Contributor

SaySayo commented Oct 18, 2021

I'd like to work on this issue.

SaySayo added a commit to SaySayo/vscode-ocaml-platform that referenced this issue Oct 18, 2021
Modified the command to set the `--set-switch` flag. Fixes (ocamllabs#655)
ulugbekna pushed a commit to SaySayo/vscode-ocaml-platform that referenced this issue Oct 20, 2021
Modified the command to set the `--set-switch` flag. Fixes (ocamllabs#655)
@ulugbekna ulugbekna linked a pull request Oct 20, 2021 that will close this issue
@ulugbekna
Copy link
Collaborator

ulugbekna commented Oct 20, 2021

Fixed in #744

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers type: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants