sdkman / sdkman-cli

The SDKMAN! Command Line Interface
https://sdkman.io
Apache License 2.0
6.06k stars 629 forks source link

Fish shell compatibility #671

Open cesards opened 5 years ago

cesards commented 5 years ago

Please tick one:

Extract script archive...
Install scripts...
Set version to 5.7.3+337 ...
Attempt update of login bash profile on OSX...
Added sdkman init snippet to /Users/xxx/.bash_profile
Attempt update of zsh profile...
Updated existing /Users/xxx/.zshrc

It adds sdkman init snippet to bash and zsh, but I'm currently using Fish (I moved from ZSH a while ago) and it doesn't seem to support it.

I might try to create a PR with the right script for Fish shell if you agree on that. And it's a good way to start my Hacktoberfest!

reitzig commented 5 years ago

If you'll forgive the plug, may I recommend sdkman-for-fish?

A draft for showing it while installing SDKMAN! is here: sdkman/sdkman-hooks/pull/9

Given that a complete rewrite in Go is underway (which will make special support for different shells obsolete, I assume), I don't think we should expect much "official" support here. I'm sure @marc0der will check out pull requests for documentation?

phatblat commented 5 years ago

There's also omf-sdk for Oh My Fish users

davinkevin commented 3 years ago

A default integration should be better πŸ‘. Like @cesards proposes, I can propose.a contribution to support that if ok for you.

With sdkman-for-fish, I have to install fisher to install it… which is another plugin to manage a sdkman.

hg1112 commented 3 years ago

Any update on this issue ?

jonasheschl commented 2 years ago

I would also be interested in using sdkman with the fish shell. Is there a way of using sdkman with fish as of now?

The sdkman-for-fish plugin sadly does not seem to work anymore. @reitzig mentioned that the rewrite in Go "will make special support for different shells obsolete". Though from what i can see sdkman does not use Go. Was the rewrite cancelled, has there been another rewrite? Is special support for different shell obsolete, in other words, does sdkman work with every shell out-of-the box some way, as implied by the reitzigs comment?

reitzig commented 2 years ago

The sdkman-for-fish plugin sadly does not seem to work anymore

While I should definitely push an update at some point, it still works for me. If you could leave your issue over in my repo, I'd appreciate it.

Was the rewrite cancelled, has there been another rewrite?

There hasn't been, and to my knowledge, there isn't one planned. As of now, sdkman is a Bash application manipulating environment variables, which means you'll need some form of wrapper to make it work in other shells.

jonasheschl commented 2 years ago

Thank you for the info.

I just looked into setting up sdkman-for-fish again, the project does indeed work. Sorry for that, my bad. I assumed the installation was broken when I saw the last commit to the repo being from 2020 and sdkman-for-fish prompting that sdkman could not be found, even though I had previously installed it.

sdkman-for-fish did successfully locate sdkman when I answered the prompt "sdkman could not be found, do you want to install it" with yes.

reitzig commented 2 years ago

Thanks, glad it worked out!

Did you run afoul of https://github.com/reitzig/sdkman-for-fish/issues/34, by any chance? If not, I'd be interested in the specifics of your setup. sdkman-for-fish is definitely supposed to find sdkman (at the default location, as of now)!

jonasheschl commented 2 years ago

It was like this for me:

A few days later, when you mentioned that sdkman-for-fish was still working for you, I attempted the installation again. This time, when sdkman-for-fish prompted me that sdkman could not be found and whether I wanted to install sdkman, I entered y.

After I entered y and hit return, sdkman-for-fish successfully found sdkman and worked without a flaw.

So not a real issue here, just a confusion on my part.

Oh, and thank you for your quick response.

ibqn commented 2 years ago

Hi guys, I am missing official support for the fish shell

marc0der commented 2 years ago

Hi @ibqn, since the whole of SDKMAN is currently written in bash, it is not possible to officially support fish shell.

dmikusa commented 2 years ago

In case it's helpful to anyone, I added this function to my fish config (~/.config/fish/config.fish). It wraps the sdk command so you can run it from your fish shell.

function sdk
    bash -c "source '~/.sdkman/bin/sdkman-init.sh'; sdk $argv[1..]"
end

and this which adds your candidates to $PATH.

fish_add_path (find ~/.sdkman/candidates/*/current/bin -maxdepth 0)

Doing this, most of the sdk commands work. I can install, remove, and set defaults, as well as use the tools installed. The only thing that definitely doesn't work is sdk use to temporarily change a version because of the way I'm wrapping the call.

gengjiawen commented 2 years ago

@dmikusa-pivotal Thx for sharing, works like a charm.

I changed to $HOME for compatibilty

function sdk
    bash -c "source '$HOME/.sdkman/bin/sdkman-init.sh'; sdk $argv[1..]"
end
vonbarnekowa commented 1 year ago

Has anyone found a solution to make sdk use work?

reitzig commented 1 year ago

If you'll forgive the plug, may I recommend sdkman-for-fish? ☝️

Long due an update, but sdk use has always worked for me. Addendum: Patched to be current with sdk as of June this year.

ElijahLynn commented 11 months ago

Thanks for the comments above, very helpful. I was getting this error on adding the path:

fish_add_path (find ~/.sdkman/candidates/*/current/bin -maxdepth 0)

fish: No matches for wildcard '~/.sdkman/candidates/*/current/bin'. See `help wildcards-globbing`.
find ~/.sdkman/candidates/*/current/bin -maxdepth 0
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
in command substitution
fish: Unknown error while evaluating command substitution
fish_add_path (find ~/.sdkman/candidates/*/current/bin -maxdepth 0)
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

And I had an empty ~/.sdkman/candidates/ directory and had to install a version of Java first. Here is my entire set of operations I used to get it worked, with the added step in the middle.

Install SDK Man with official instructions:

curl -s "https://get.sdkman.io" | bash
# vim ~/.config/fish/functions/sdk.fish:
function sdk
    bash -c "source '$HOME/.sdkman/bin/sdkman-init.sh'; sdk $argv[1..]"
end
# install a version of Java
sdk install java 17.0.2-open
# Set it as default
sdk default java 17.0.2-open

setting java 17.0.2-open as the default version for all shells.

Then this worked, and I had to add this to config.fish to make it persistent across shells:

fish_add_path (find "~/.sdkman/candidates/*/current/bin" -maxdepth 0)
Kambi-V commented 9 months ago

in order for

fish_add_path (find "~/.sdkman/candidates/*/current/bin" -maxdepth 0)

to work replace * with the actual package, eg.

fish_add_path (find "$HOME/.sdkman/candidates/maven/current/bin" -maxdepth 0)
fish_add_path (find "$HOME/.sdkman/candidates/kotlin/current/bin" -maxdepth 0)
fish_add_path (find "$HOME/.sdkman/candidates/java/current/bin" -maxdepth 0)
fish_add_path (find "$HOME/.sdkman/candidates/gradle/current/bin" -maxdepth 0)

also replace ~ with $HOME

$HOME represents ~ , i.e, home/user

viet-wego commented 2 months ago

Thanks for the comments above, very helpful. I was getting this error on adding the path:

fish_add_path (find ~/.sdkman/candidates/*/current/bin -maxdepth 0)

fish: No matches for wildcard '~/.sdkman/candidates/*/current/bin'. See `help wildcards-globbing`.
find ~/.sdkman/candidates/*/current/bin -maxdepth 0
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
in command substitution
fish: Unknown error while evaluating command substitution
fish_add_path (find ~/.sdkman/candidates/*/current/bin -maxdepth 0)
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

And I had an empty ~/.sdkman/candidates/ directory and had to install a version of Java first. Here is my entire set of operations I used to get it worked, with the added step in the middle.

Install SDK Man with official instructions:

curl -s "https://get.sdkman.io" | bash
# vim ~/.config/fish/functions/sdk.fish:
function sdk
    bash -c "source '$HOME/.sdkman/bin/sdkman-init.sh'; sdk $argv[1..]"
end
# install a version of Java
sdk install java 17.0.2-open
# Set it as default
sdk default java 17.0.2-open

setting java 17.0.2-open as the default version for all shells.

Then this worked, and I had to add this to config.fish to make it persistent across shells:

fish_add_path (find "~/.sdkman/candidates/*/current/bin" -maxdepth 0)

Thank you for the tip. This saves me hours of trying to do it myself. πŸ™πŸΌ