reitzig / sdkman-for-fish

Adds support for SDKMAN! to fish
MIT License
280 stars 13 forks source link

`sdk use` does not have any effect #8

Closed rahulsom closed 5 years ago

rahulsom commented 5 years ago

This is what I see.

 ~/src  sdk ls java                                                                                                                                                                                                  Fri Jul 13 22:12:14 2018

================================================================================
Available Java Versions
================================================================================
     9.0.7-zulu
   + 9.0.4-oracle
     9.0.4-openjdk
   + 9.0.1-oracle
   + 9.0.0-zulu
 > + 8u141-oracle
   + 8u131
   * 8.0.172-zulu
     8.0.171-oracle
   + 7u79
     7.0.181-zulu
   + 6u65
   * 10.0.1-zulu
     10.0.1-oracle
     10.0.0-openjdk

================================================================================
+ - local version
* - installed
> - currently in use
================================================================================
 ~/src  sdk u java 10.0.1-zulu                                                                                                                                                                              1507ms  Fri Jul 13 22:12:19 2018

Using java version 10.0.1-zulu in this shell.
 ~/src  sdk ls java                                                                                                                                                                                         1453ms  Fri Jul 13 22:12:32 2018

================================================================================
Available Java Versions
================================================================================
     9.0.7-zulu
   + 9.0.4-oracle
     9.0.4-openjdk
   + 9.0.1-oracle
   + 9.0.0-zulu
 > + 8u141-oracle
   + 8u131
   * 8.0.172-zulu
     8.0.171-oracle
   + 7u79
     7.0.181-zulu
   + 6u65
   * 10.0.1-zulu
     10.0.1-oracle
     10.0.0-openjdk

================================================================================
+ - local version
* - installed
> - currently in use
================================================================================
 ~/src                                                                                                                                                                                                      1463ms  Fri Jul 13 22:12:37 2018
reitzig commented 5 years ago

Since this project ist mostly about completion, I checked that. Seems to work as expected on my end:

image

image

image

As for sdk use not doing what it's supposed to do: can confirm. Works with bash, so it's about the fish wrapper.

Fish calls bash to perform sdk actions; I assume bash changed the version in the current (bash) shell, which then exited. This is a conceptual issue, not a programming bug. Will have to think and tinker; any input appreciated.

FWIW, sdk default works just fine.

reitzig commented 5 years ago

sdk directly manipulates PATH. Therefore, the solution is to copy PATH from the bash subshell to the current shell.

Thanks for your report!

Tests performed

Straight-forward change

> java -version
java version "10.0.1" 2018-04-17
> sdk u java 8.0.171-oracle 

Using java version 8.0.171-oracle in this shell.
> java -version
java version "1.8.0_171"

Change carries over to subshell

> java -version
java version "10.0.1" 2018-04-17
raphael@donald ~> sdk u java 8.0.171-oracle 

Using java version 8.0.171-oracle in this shell.
> fish
Welcome to fish, the friendly interactive shell
> java -version
java version "1.8.0_171"

Change does not carry over to parent shell

> java -version
java version "10.0.1" 2018-04-17
raphael@donald ~> fish
Welcome to fish, the friendly interactive shell
raphael@donald ~> sdk u java 8.0.171-oracle 

Using java version 8.0.171-oracle in this shell.
raphael@donald ~> java -version
java version "1.8.0_171"
raphael@donald ~> exit
raphael@donald ~> java -version
java version "10.0.1" 2018-04-17
reitzig commented 5 years ago

Nota bene: fish-sdk now copies PATH always (as long as sdk succeeds). I'm sure issues can be caused by that. I might also have missed some escaping or another so some PATH entries might break the script. Awaiting reports.

reitzig commented 5 years ago

This could provide an alternative: https://github.com/oh-my-fish/plugin-foreign-env