Git Product home page Git Product logo

sdkman-for-fish's Introduction

SDKMAN! for fish

license release GitHub release date Test CodeQL

Makes command sdk from SDKMAN! usable from fish, including auto-completion. Also adds binaries from installed SDKs to the PATH.

Version 2.1.0 has been tested with

  • fish 3.7 and
  • SDKMAN! 5.18.2 on
  • Ubuntu 22.04 LTS and macOS 14.4

Install

With fisher (install separately):

fisher install reitzig/[email protected]

Note:

  • Only compatible with fisher v4 upwards; v3 is no longer supported.
  • You have to install SDKMAN! separately.
  • If you have installed SDKMAN! at a custom location, you need to either
    • set environment variable SDKMAN_DIR to that path using your preferred method, or
    • add
      set -g __sdkman_custom_dir /your/path/to/sdkman
      to a fish config file run before .config/fish/conf.d/sdk.fish; for example, you can use .config/fish/conf.d/config_sdk.fish.
    • If both are set, __sdkman_custom_dir is used.

Usage

It's all in the background; you should be able to run sdk and binaries installed with sdk as you would expect.

Contribute

When you propose changes, please run the tests at least on one platform before creating a pull request.

As the tests may mess up your machine -- you have been warned! -- the recommended way is to run them in a Docker container:

docker build -t sdkman-for-fish-tests -f test/Dockerfile .
docker run --rm -it sdkman-for-fish-tests

A run configuration for Jetbrains IDEs is included.

It is a also possible to run individual features, for instance:

docker run --rm sdkman-for-fish-tests features/completions.feature

Acknowledgements

sdkman-for-fish's People

Contributors

atallahade avatar bryan2333 avatar dependabot[bot] avatar reitzig avatar zambito1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

sdkman-for-fish's Issues

Do not complete sdk unless it is installed

I don't have SDKMAN! installed yet, but I still see:

> sdk <TAB>
b          (Display broadcast message)  h       (Display help message)  rm         (Uninstall version)
broadcast  (Display broadcast message)  help    (Display help message)  selfupdate     (Update sdkman)
c            (Display current version)  i        (Install new version)  u       (Use specific version)
current      (Display current version)  install  (Install new version)  uninstall  (Uninstall version)
…and 3 more rows

Instead, sdk should be shown as red (as other unavailable commands). There should be no auto-completion on its parameters.

Test documented installation path

Since the README tells people to use fisher to install, we should test that.

While I can not reproduce locally, #32 and #33 suggest that there is some issue.
As per jorgebucaran/fisher#557, fisher does not seem to have a general problem, either.

Add a (nightly?) build for different platforms that uses fisher to install sdkman-for-fish (and then SDKMAN? through that our routine?).

Errors in initialization scripts (Windows + mingw)

I want to use this feature in mingw on Windows. When i try the fresh install with fisher install reitzig/sdkman-for-fish this just work, but in bootstrap of fish throw this:

fish: Unknown command: env
~/.config/fish/conf.d/sdk.fish (line 22):
          or    env test "$__fish_sdkman_init" -nt "$__fish_sdkman_noexpor
t_init"
                ^
from sourcing file ~/.config/fish/conf.d/sdk.fish
        called on line 253 of file /usr/share/fish/config.fish
from sourcing file /usr/share/fish/config.fish
        called during startup
fish: Unknown command: mktemp
~/.config/fish/conf.d/sdk.fish (line 1):
mktemp
^
in command substitution
        called on line 40 of file ~/.config/fish/conf.d/sdk.fish
in function '__fish_sdkman_run_in_bash' with arguments 'source\ /home/onie
lsen/.sdkman/bin/sdkman-init.sh'
        called on line 82 of file ~/.config/fish/conf.d/sdk.fish
from sourcing file ~/.config/fish/conf.d/sdk.fish
        called on line 253 of file /usr/share/fish/config.fish
from sourcing file /usr/share/fish/config.fish
        called during startup
~/.config/fish/conf.d/sdk.fish (line 40): Unknown error while evaluating c
ommand substitution
    set pipe (mktemp)
             ^
in function '__fish_sdkman_run_in_bash' with arguments 'source\ /home/onie
lsen/.sdkman/bin/sdkman-init.sh'
        called on line 82 of file ~/.config/fish/conf.d/sdk.fish
from sourcing file ~/.config/fish/conf.d/sdk.fish
        called on line 253 of file /usr/share/fish/config.fish
from sourcing file /usr/share/fish/config.fish
        called during startup
/bin/bash: /home/onielsen/.sdkman/bin/sdkman-init.sh: No such file or dire
ctory
/bin/bash: -c: line 1: syntax error near unexpected token `;'
/bin/bash: -c: line 1: `             echo -e "0" > ;'
fish: Unknown command: cat
~/.config/fish/conf.d/sdk.fish (line 1):
cat $pipe; rm $pipe
^
in command substitution
in function '__fish_sdkman_run_in_bash' with arguments 'source\ /home/onielsen/.sdkman/bin/sdkman-init.sh'
        called on line 82 of file ~/.config/fish/conf.d/sdk.fish
from sourcing file ~/.config/fish/conf.d/sdk.fish
        called on line 253 of file /usr/share/fish/config.fish
from sourcing file /usr/share/fish/config.fish
        called during startup
fish: Unknown command: rm
~/.config/fish/conf.d/sdk.fish (line 1):
cat $pipe; rm $pipe
           ^
in command substitution
        called on line 46 of file ~/.config/fish/conf.d/sdk.fish
in function '__fish_sdkman_run_in_bash' with arguments 'source\ /home/onielsen/.sdkman/bin/sdkman-init.sh'
        called on line 82 of file ~/.config/fish/conf.d/sdk.fish
from sourcing file ~/.config/fish/conf.d/sdk.fish
        called on line 253 of file /usr/share/fish/config.fish
from sourcing file /usr/share/fish/config.fish
        called during startup
~/.config/fish/conf.d/sdk.fish (line 46): Unknown error while evaluating command substitution
    set bashDump (cat $pipe; rm $pipe)
                 ^
in function '__fish_sdkman_run_in_bash' with arguments 'source\ /home/onielsen/.sdkman/bin/sdkman-init.sh'
        called on line 82 of file ~/.config/fish/conf.d/sdk.fish
from sourcing file ~/.config/fish/conf.d/sdk.fish
        called on line 253 of file /usr/share/fish/config.fish
from sourcing file /usr/share/fish/config.fish
        called during startup
[: Missing argument at index 3
= 0
    ^
~/.config/fish/conf.d/sdk.fish (line 53):
    if [ $sdkStatus = 0 ]
       ^
in function '__fish_sdkman_run_in_bash' with arguments 'source\ /home/onielsen/.sdkman/bin/sdkman-init.sh'
        called on line 82 of file ~/.config/fish/conf.d/sdk.fish
from sourcing file ~/.config/fish/conf.d/sdk.fish
        called on line 253 of file /usr/share/fish/config.fish
from sourcing file /usr/share/fish/config.fish
        called during startup

And sdk not works anymore.

PATH entry of de-installed SDKs persists

After uninstalling all versions of a candidate, fish greets us with an error:

set: Warning: $PATH entry "/home/raphael/.sdkman/candidates/crash/current/bin" is not valid (No such file or directory)
Welcome to fish, the friendly interactive shell

Automated testing

It would be great to have continuous testing across a range of combinations of fish/sdk versions.

I don't have any idea how to test shell I/O (in particular completions) in an efficient way, though. Input appreciated.

Remove redundancies in completions

Currently, the pattern is

complete -c sdk -f -n '__fish_sdkman_no_command' -a 'cmd' -d 'Some command'
complete -c sdk -f -n '__fish_sdkman_no_command' -a 'c' -d 'Some command'
complete -c sdk -f -n '__fish_sdkman_using_command cmd' -a "(__fish_sdkman_candidates)"  
complete -c sdk -f -n '__fish_sdkman_using_command c' -a "(__fish_sdkman_candidates)"  

These can be combined like so:

complete -c sdk -f -n '__fish_sdkman_no_command' -s 'c' -l 'cmd' -d 'Some command'
complete -c sdk -f -n '__fish_sdkman_using_command cmd' -a "(__fish_sdkman_candidates)"  # ?

This not only cleans up the code, but also removes the duplicates from the completion list.

Apply to all completions.

Respect globally set SDKMAN_DIR

Re #46:

I set SDKMAN_DIR globally, through environment.d with system. It should not be over-written by sdk.fish.

In my opinion, if both are defined, __sdkman_custom_dir should be preferred.

Labelling this as bug since, as @xtexChooser mentions, the original sdkman-init.sh does blindly trust and use SDKMAN_DIR. I think that's probably a bad idea, but well.

[Bug] Cannt find SDKMAN! for vscode terminal, but work for Windows Terminal.

Somehow when I type sdk in vscode terminal, it always print:

  • You don't seem to have SDKMAN! installed. Install now? [y/N]

even after I set __sdkman_custom_dir in my fish config. And, when I type y, I can see:

  • You already have SDKMAN installed.

but it's not work. You don't seem to have SDKMAN!... come again when I try sdk after.

What's even stranger is this things only happen on my vscode terminal, I can use sdk in my Windows Terminal.

Environment

  • Windows 11
  • WSL version: 2.1.0.0, Ubuntu 20 LTS
  • VS Code 1.87.2
  • fish version 3.3.1

I looked at the vscode extensions and only the git extension contributed to the environment variables

Support sdkman extensions

SDKMAN! supports extensions. Currently, they are invisible from fish (but should be callable, since the generated sdk call is correct).

Add general completion by scanning the $SDKMAN_DIR/ext folder for sdkman-<command>.sh files. Add <command> as completable command (description?). Further parameters probably can not be completed with a general solution.

Update to sdkman! 5.18.x

Current support level on dev: 5.11.0

Check the changelog and see if there's something to be done.

(Successful) Calls to sdk overwrite the environment, including PATH

Expected

 $ java -version
java version "10.0.1" 2018-04-17
$ sdk use java 8.0.171-oracle 

Using java version 8.0.171-oracle in this shell.
$ java -version
java version "1.8.0_171"
$ sdk install ant foo
<snip>
$ java -version
java version  "1.8.0_171"

Actual

 $ java -version
java version "10.0.1" 2018-04-17
$ sdk use java 8.0.171-oracle 

Using java version 8.0.171-oracle in this shell.
$ java -version
java version "1.8.0_171"
$ sdk install ant foo
<snip>
$ java -version
java version "10.0.1" 2018-04-17

Analysis

We delegate command source $sdkman_init && sdk $argv to bash. We have to, because otherwise function sdk is not defined in that shell.

This initialization overwrites the environment variables inherited from the parent fish shell, including PATH (relevant) and SDKMAN_* (probably not?). After it completes, fish copies over the environment. It has to, otherwise no command would have any effect (cf issue #8).

Plan

Without changes in SDKMAN! that separate function declaration from environment initialization, it's probably gonna be hacky.

Idea: hard-code resetting the environment into the delegation command (between source and sdk).

Use full paths to core Unix commands in functions

The sdk functions currently assume that the standard Unix commands are first on the path and unaliased (e.g., conf.d/sdk.fish#L45), so if you have something like rm aliased to 'rm -i', running sdk will prompt you every time with:

rm: remove regular file '/tmp/tmp.OvvGBzqDYa'? y

This can be fixed by using the full paths to any standard Unix commands (e.g., /bin/rm $pipe instead of rm $pipe).

Missing fishfile

I see that on your fish plugin you use the edc/bass dependency. For that kind of deps use the fishfile format.

Or simply echo "edc/bass" >> fishfile.

Make compatible with macOS

Due to differences in default programs, sdkman-for-fish currently doesn't work on macOS. Issues include

  • non-GNU stat (see also this comment),
  • sha256sum unavailable (test only).

We'll need tests and then see what we can do about whatever pops up.

Copy JAVA_HOME over correctly

Environment variable JAVA_HOME doesn't survive the transition:

— ~ $ echo $JAVA_HOME

— ~ $ bash
rreitzig@raphael-Ubuntu:~$ echo $JAVA_HOME
/home/DHTP/rreitzig/.sdkman/candidates/java/current

Fix that, and check for "bigger" issues.

Probably relates to the hack in #19.

Can't add the repo

Fish version: 3.1.0
Fisher version: fisher version 3.2.10 ~/.config/fish/functions/fisher.fish

I tried to add the repo but it failes everytime with the following message:

fetching https://codeload.github.com/reitzig/sdkman-for-fish/tar.gz/master
mv: das angegebene Ziel '/home/sven/.cache/fisher/github.com/reitzig/sdkman-for-fish' ist kein Verzeichnis
cp: der Aufruf von stat für '/home/sven/.cache/fisher/github.com/reitzig/sdkman-for-fish' ist nicht möglich: No such file or directory
done in 0.70s

❰sven❙~❱✔≻ fisher
fisher: nothing to commit -- try adding some packages
❰sven❙~❱✔≻ cat .config/fish/fishfile

I ran

❰sven❙~❱✔≻ fisher add reitzig/sdkman-for-fish
fetching https://codeload.github.com/reitzig/sdkman-for-fish/tar.gz/master
mv: das angegebene Ziel '/home/sven/.cache/fisher/github.com/reitzig/sdkman-for-fish' ist kein Verzeichnis
cp: der Aufruf von stat für '/home/sven/.cache/fisher/github.com/reitzig/sdkman-for-fish' ist nicht möglich: No such file or directory
done in 0.70s

Fix auto-completion for installed versions

Currently, we get this:

> sdk default java <TAB>
ls: cannot access '/home/raphael/.sdkman/java': No such file or directory

The path should be .sdkman/candidates/java/.

Complete install local version

According to the docs, this is valid:

sdk install groovy 3.0.0-SNAPSHOT /path/to/groovy-3.0.0-SNAPSHOT

This was missed (because it's not in the output of sdk). Add completion of files (ideally: directories) as fourth parameter to install.

Error with usage of `stat` in `sdk.fish` when running `fisher`

(Update: i now see that this issue already reports the problem and there are attempts underway to fix it. Feel free to close as subsumed under the earlier issue)

I see the following error (appears to come from sdk.fish) when running fisher

...
linking ~/.config/fish/conf.d/sdk.fish
stat: illegal option -- c
usage: stat [-FlLnqrsx] [-f format] [-t timefmt] [file ...]
updated 1 package in 1.20s
...

I am on macOS Mojave, version 10.14.6

$ uname -a
Darwin ELSOXFM-189408 18.7.0 Darwin Kernel Version 18.7.0: Tue Aug 20 16:57:14 PDT 2019; root:xnu-4903.271.2~2/RELEASE_X86_64 x86_64

$ fish --version
fish, version 3.0.2

Enabling offline mode has no effect

Expected

$ sdk offline enable
Offline mode enabled.
$ sdk install java 7.0.181-zulu
Stop! java 7.0.181-zulu is not available while offline.

Actual

Offline mode enabled.
$ sdk install java 7.0.181-zulu

Downloading: java 7.0.181-zulu
<snip>

Analysis

The problem is that sdk uses an environment variable ($SDKMAN_OFFLINE_MODE, to be precise) to signal offline mode across runs. This environment variable is not captured from the nested bash call to the fish session.

Plan

Capture all $SDKMAN_* variables, thereby fixing all unknown issues with similar cause. Use the same method as for capuring $PATH. Add tests.

Silent block when sdk prompts

When e.g. sdk upgrade prompts the user for input, fish-sdk does not show the prompt and silently locks.

Regression after #8, I think.

`sdk use` does not have any effect

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.