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

Fish shell compatibility #671

Open
1 task done
cesards opened this issue Oct 1, 2018 · 18 comments
Open
1 task done

Fish shell compatibility #671

cesards opened this issue Oct 1, 2018 · 18 comments

Comments

@cesards
Copy link

cesards commented Oct 1, 2018

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
Copy link
Contributor

reitzig commented Nov 1, 2018

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
Copy link

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

@davinkevin
Copy link

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
Copy link

hg1112 commented Apr 17, 2021

Any update on this issue ?

@jonasheschl
Copy link

jonasheschl commented Jan 9, 2022

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
Copy link
Contributor

reitzig commented Jan 10, 2022

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
Copy link

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
Copy link
Contributor

reitzig commented Jan 10, 2022

Thanks, glad it worked out!

Did you run afoul of reitzig/sdkman-for-fish#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
Copy link

jonasheschl commented Jan 16, 2022

It was like this for me:

  • I installed sdkman in the default path
  • I tried to install sdkman-for-fish
  • While installing, sdkman-for-fish prompted me that sdkman could not be found, and if i wanted to install it [y/N]
  • Since I had previously installed sdkman, I assumed that sdkman-for-fish was broken and aborted the install

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
Copy link

ibqn commented Apr 5, 2022

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

@marc0der
Copy link
Member

marc0der commented Apr 5, 2022

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

@dmikusa
Copy link

dmikusa commented May 18, 2022

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
Copy link

@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
Copy link

Has anyone found a solution to make sdk use work?

@reitzig
Copy link
Contributor

reitzig commented Jun 1, 2023

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
Copy link

ElijahLynn commented Oct 16, 2023

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
Copy link

Kambi-V commented Nov 25, 2023

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
Copy link

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. 🙏🏼

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

No branches or pull requests