sdkman / sdkman-cli

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

'list installed' command? #466

Closed eprozium closed 3 years ago

eprozium commented 7 years ago

Hi,

How to find what is installed with Sdkman?

There doesn't seem to be a sdk list installed commands, and just calling sdk list simply shows all potential SDKs to install.

Thanks.

marc0der commented 7 years ago

Please refrain from using Github issues for usage questions. Use the Gitter user-issues chat instead.

eprozium commented 7 years ago

@marc0der it's not a usage question :) .

marc0der commented 7 years ago

Sorry for sounding harsh, that was not the intention. The website usage page clearly states that the command to use here is sdk current.

eprozium commented 7 years ago

Thank you very much. Not sure how I missed that one :( .

mvysny commented 7 years ago

Thanks, helped me as well. Intuitively I also went for sdk list --installed or something like that.

btassone commented 6 years ago

Probably a good thing to consider changing sdk list, to sdk available. 1 makes more sense, and 2 that frees you up for using sdk list to show the list of installed. sdk current isn't exactly clear on what it does in its name as sdk list would be for showing all installed. Better yet, get rid of sdk current and just add a sdk list --installed. Probably even better.

marc0der commented 4 years ago

@btassone apologies for never replying on this but don't think I ever got notified about your comment.

I agree that renaming list to available would make a lot of sense. It would however be very confusing for all our long-time users though.

Regarding the other suggestion of qualifying sdk list with a --installed flag, I don't think this is a good idea as it goes against the command syntax of sdkman. We don't use flags like this anywhere else. The syntax always (strictly) falls into the pattern:

sdk <command> [version] [qualifier]

If we introduce something better or more intuitive it should fall into the same pattern. In other words, sdk list installed would fall into this pattern, but then what does sdk list do if we rename it to available?

My suggestion that we bring about such change in small steps: Leave sdk list to be what it currently is for the time being, then introduce the installed qualifier on top of the list command to replace current. wdyt?

wemu commented 4 years ago

I think the last suggestion sounds best. "sounds" meaning the way it reads or is spoken. so sdk list installed and sdk list available reads nice and looks intuitive. sdk list could stay the same for some time and then change or simply point to the other statements.

tb582 commented 4 years ago

was this ever done? - confused me for a bit this AM before some googling lol

marc0der commented 4 years ago

@tb582 no, still waiting for the pull requests to come in :laughing:

marc0der commented 4 years ago

@lcxw the beauty of open source is that you can contribute a solution.

rgoldberg commented 4 years ago

sdk list could continue as an alias for sdk available. sdk installed could implement the new functionality. I don't see a need to insert list after sdk and before available|installed.

leo-from-spb commented 4 years ago

I've installed several javas, how can I list them all with their paths? The 'sdk current' shows only the current one.

ibethencourt commented 4 years ago

The only way I've found is:

sdk list java | grep installed

Hope that helps

jamius19 commented 4 years ago

Unless I'm missing something, sdk current only shows the currently active JDK version. It doesn't list all the installed versions.

As per @ibethencourt answer, this is the only way (AFAIK) for checking all currently installed versions, which I'd love to have in SdkMan itself!

If I'm missing something please correct me. Have a nice day!

marstalk commented 4 years ago

I don't think it's an issue rather than inprovment. As @ibethencourt saying, sdk list java | grep installed is such a good way to solve the issue.

aairey commented 4 years ago

This doesn't work if you want to see all candidates their installed versions.

So I resorted to this:

➜ tree -L 2 ~/.sdkman/candidates/
/home/aairey/.sdkman/candidates/
└── gradle
    ├── 6.4
    └── current -> /home/aairey/.sdkman/candidates/gradle/6.4

3 directories, 0 files

This works as long as you use the default local-path for your candidates.

nautilor commented 4 years ago

added this into my .zshrc

sdkman() {
        [[ "$1" == "installed" ]] && sdk list $2 | grep installed || sdk "$@"
}

now i can run sdkman installed java

works great

Abhinav1217 commented 4 years ago

Stumbled here because I was searching for something similar. I have 4 jdk's installed for different purposes. so when I wanted to switch between, for example jdk 8 to jdk 11, I always forget the exact identifier, "11.0.7.hs-adpt" So I was hoping there was some command which just list just the installed java instead of entire list which require me to scroll up and search for the correct identifier.

This would also be useful in uninstalling redundent/unneeded versions. We can list the installed kotlin and with information in front of us we can type commands easily.

I am surprised this isn't readily available since the list of sdk and jdk has gotten really large. An ideal case would be something like sdk switch java, which would show an alternatives like menu to switch java version.

rgoldberg commented 4 years ago

@Abhinav1217: If you use zsh, oh-my-zsh has command line argument completion for sdkman.

Commands that only work with installed versions will only display / autocomplete installed versions.

I don’t know if sdkman argument completion exists for bash, or how well any such argument completion works.

Abhinav1217 commented 4 years ago

I am on primarily bash, But I have omz installed I can switch to it temporarily. Currently I set sdkman to offline to limit the list to installed only.

barmalei commented 3 years ago

Hi Guys from 2020. Is there a SDKMAN command that list all locally installed packages or it is better to back to the question in 2021 or 2022 ?

Abhinav1217 commented 3 years ago

@barmalei Not yet. Best I usually work with is set sdkman to offline and then list Java, It shows only installed versions, making it easier to switch. I did create a script for sdkman to do it automatically, but I usually ends up typing whole set as I distro-hop quite frequently.

gaochundong commented 3 years ago

+1

antonmry commented 3 years ago

I use shell autocompletion with sdk use and it works well for me to see what versions are installed. Review https://github.com/sdkman/sdkman-cli/issues/83 to see how to enable it for your favorite shell

1pavanb commented 3 years ago

The official sdk plugin for zsh is already available in your ohmyzsh installation. Just enable it in your plugins list .zshrc file and restart the terminal. plugins=(sdk)

helpermethod commented 3 years ago

Hi!

With Bash completion now in place, we could display the list of installed candidates when autocompleting the use command.

That way we wouldn't need to introduce another command only for showing installed versions. @marc0der wdyt?

mikybars commented 3 years ago

I came up with a pretty geek solution myself by means of a proxy function for the sdkcommand:

function sdk_proxy {
  if (( $# == 2 )) && [[ $1 =~ ^(u|use)$ ]]; then
    sdk use $candidate $(sdk_fuzzy_find_local_version $2)
  else
    sdk "$@"
  fi
}

(The exact mechanism for turning the above into a proxy function in bash is irrelevant here but you can check out https://frederic-hemberger.de/articles/speed-up-initial-zsh-startup-with-lazy-loading/ in case you're interested).

The snippet above just says that whenever I invoke the use subcommand followed by a candidate BUT NOT a version (i.e. sdk use java or sdk u java) then I plug in a custom fuzzy search:

function sdk_fuzzy_find_local_version {
  __sdkman_build_version_csv $1 | 
    tr ',' '\n' | 
    sort -r -n | 
    fzf -d '\.' --nth 1
}

I know this is a bit fragile as I'm relying on an internal sdkman function (named __sdkman_build_version_csv) that is bound to change (or be gone) in the future. But, after all, this is just a workaround and besides I ❤️ proxies ¯_(ツ)_/¯

marc0der commented 3 years ago

@helpermethod is it worth keeping this issue open until we have a working solution for ZSH too?

marc0der commented 3 years ago

@mperezi very cool, and it must have been fun doing this :smile: However, I certainly would recommend that you use the command line completion that @helpermethod just implemented instead. I'll also look at doing the same for ZSH soon.

marc0der commented 3 years ago

Re-opening this issue until ZSH is also supported. This will involve porting the oh-my-zsh plugin back into our completion mechanism.

helpermethod commented 3 years ago

@marc0der Yes, we should keep the issue open. I can take a stab at ZSH this evening, but I also wouldn't be to sad if anyone else takes over the ZSH completion part 😄.

marc0der commented 3 years ago

I can have a crack at it sometime, you've already done ample with bash completion.

marc0der commented 3 years ago

The autocompletion functionality is now available for both bash and ZSH. It was released as v5.11.1.

franco-circleup commented 3 years ago

For zsh I cannot get shell completion enabled from using the instructions: https://sdkman.io/usage#completion

I tried them as-is as well as replacing bash with zsh.

helpermethod commented 3 years ago

Hi @franco-circleup, it seems an error has sneaked into the docs.

The correct command is

source <(sdk completion bash)

or for zsh

source <(sdk completion zsh)

I'll fix the documentation tomorrow. Sorry for the inconvenience!

franco-circleup commented 3 years ago

That works perfectly, thanks!

Abhinav1217 commented 3 years ago

I have enabled completion, But I only get completion for first parameter.

  1. I type sdk, double tap the tab key.
  2. I get list of accepted parameter, I select use then type java

What is expected

  1. double tab should list installed java candidates. What actually happens.
  2. double tab just list all the folders and files ( this is, AFAIK, the default behavior of bash shell )
helpermethod commented 3 years ago

Hi @Abhinav1217,

works fine for me. Are you using the bash or zsh completion? Note that use will only complete the locally installed versions, not all Java versions available.

image

Abhinav1217 commented 3 years ago

I am using bash completion, I updated sdk and recreated sdk completion, It did not work. Then based on someone's advice on reddit,

Reason given was that sometimes, sdkman prints broadcast messages which will make completion fails. I stumbled upon it as I was occasionally getting this issue whenever I launch new terminal. Which I suspected was something to do with sdk completion but wanted to be sure before I come here.

bash_error

When I created the 00_sdkman_bash_completion file, I did find the broadcast message in the output. I removed it issue was gone, Only downside is that now I would have to manually update the completion file from time to time.

This issue is resolved for me, unless broadcast message should not have been printed when subcommand is completion. In that case, I have no idea why I got it.

marc0der commented 3 years ago

Hi @Abhinav1217, we are already aware of this issue and tracking it in #912. We should have a fix out for this soon. In the meanwhile, please source the completion file directly from your profile rather than using the completion command.

bentolor commented 2 years ago

Sorry to resurrect this issue that started rather unfortunate.

I'm a fish shell user and hence only got to use sdk!man by omf i sdk. I stumbled over exact the same issue as OP, and after scrolling through this issue I feel that it is still open and very relevant. Even more: I still don't know how to achieve my query!

For illustration. This is what i.e. omf tells you after simply typing omf: grafik I immediately understand: omf l is the way to go.

I was really strained looking at the sdk output: grafik

  1. I never would have assumed/understood that sdk current at least reveals some of the installed candidates
  2. The aforementioned sdk list | grep installed does not list any hits at all
  3. I understood that the rest of this tickets addressed only user-specific shell hack workarounds. Not the thing I'd expect from a package manager.

I'd still propose, that this issue is still relevant and an easy command to the list the locally installed packages should be offered and easily discoverable from the CLI.

I feel that should not need to become a shell programming expert or documentation archaeologist to fulfil this task… For me this sounds like a very, very easy and task and undoubtedly relevant functionality. Anybody willing to explain me the backgrounds for this discussion which is ongoing for more than five years?

loopmode commented 2 years ago

I agree with @bentolor What's the expectation of the maintainers? For the cimmunity to create a fork just for the sake of one useful feature that is very very easy to implement without any risk for the existing functionality? (e.g. add an explicit command)

pstephenwille commented 1 year ago

still no way to list the installed versions?

olledencker commented 1 year ago

I solved it by sdk list java|grep installed

mikymigs commented 1 year ago

It works but it's workaround... Also I have some installs that have the label "local only", so I have to use: sdk list java | grep -e installed -e local This thread if full of workarounds but there's no doubt that some kind of a sdk list installed command would be much more user friendly.

marc0der commented 1 year ago

Point taken. I'll certainly include a flag listing only installed versions when I rewrite this command.

MTyson commented 1 year ago

Guys, sdkman is awesome, it's insane that there isn't a simple in-framework way to say: "What are my installed java versions?" and "let me pick which one to make default" - simply.

marc0der commented 1 year ago

@MTyson It's insanely simple!

$ sdk default java <tab>

Now pick the one you want to make default. As simple as you can get :smile:

That said, I'll still add the new flag mentioned above when this command is rewritten in Rust.

GlennVanSchil commented 1 year ago

It works but it's workaround... Also I have some installs that have the label "local only", so I have to use: sdk list java | grep -e installed -e local This thread if full of workarounds but there's no doubt that some kind of a sdk list installed command would be much more user friendly.

This was the solution for me, just grep -e installed did not contain all my local installed versions