From e41ccb9ce87b04f35c82d56dd37824883dd7adb5 Mon Sep 17 00:00:00 2001 From: Raphael Reitzig <4246780+reitzig@users.noreply.github.com> Date: Tue, 5 Nov 2019 02:36:22 +0100 Subject: [PATCH] Offer to install SDKMAN! if not already installed. Fixes issue #26 Also: - Change language in README to clarify that SDKMAN! is not included. - Polishes to `.editorconfig`. --- .editorconfig | 9 ++++++++- README.md | 9 ++++++--- functions/sdk.fish | 41 ++++++++++++++++++++++++++++++++++------- test/reinitialize.fish | 2 ++ 4 files changed, 50 insertions(+), 11 deletions(-) diff --git a/.editorconfig b/.editorconfig index 0009889..4110381 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,5 +1,12 @@ +root = true + [*] +charset = utf-8 +end_of_line = lf indent_style = space -indent_size = 2 +indent_size = 4 trim_trailing_whitespace = true insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false diff --git a/README.md b/README.md index c59d15b..c5ace6f 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ [![Build Status][travis-badge]][travis-link] -Makes command `sdk` from [SDKMAN!] available in fish. -Also provides auto-completion and adds binaries from installed SDKs to the PATH. +Makes command `sdk` from [SDKMAN!] usable from fish, including auto-completion. +Also adds binaries from installed SDKs to the PATH. Tested with fish 2.7.1 and 3.0.2, and SDKMAN! 5.7.3. @@ -15,7 +15,10 @@ With [fisher] (install separately): fisher add reitzig/sdkman-for-fish ``` -_Note:_ Only compatible with fisher v3 upwards; v2 is no longer supported. +_Note:_ + + - Only compatible with fisher v3 upwards; v2 is no longer supported. + - You have to install [SDKMAN!] separately. ## Usage diff --git a/functions/sdk.fish b/functions/sdk.fish index 8a5dd8d..1bc2a16 100644 --- a/functions/sdk.fish +++ b/functions/sdk.fish @@ -1,9 +1,36 @@ -# Guard: SDKMAN! needs to be installed -if not test -f "$__fish_sdkman_init" - exit 0 -end - -# Declare the sdk command for fish function sdk -d "Manage SDKs" - __fish_sdkman_run_in_bash "source \"$__fish_sdkman_noexport_init\" && sdk $argv" + # Guard: SDKMAN! needs to be installed + if not test -f "$__fish_sdkman_init" + # Propose to install SDKMAN! + + function read_confirm + while true + read -l -P "$argv[1] [y/N] " confirm + + switch $confirm + case Y y + return 0 + case '' N n + return 1 + end + end + end + + if read_confirm "You don't seem to have SDKMAN! installed. Install now?" + if not which curl > /dev/null + echo "curl required" + return 1 + end + if not which bash > /dev/null + echo "bash required" + return 1 + end + + curl -s "https://get.sdkman.io" | bash | sed '/All done!/q' + echo "Please open a new terminal/shell to load SDKMAN!" + end + else + # Declare the _actual_ sdk command for fish + __fish_sdkman_run_in_bash "source \"$__fish_sdkman_noexport_init\" && sdk $argv" + end end diff --git a/test/reinitialize.fish b/test/reinitialize.fish index 50543aa..564e74b 100755 --- a/test/reinitialize.fish +++ b/test/reinitialize.fish @@ -23,3 +23,5 @@ begin exit 1 end end + +# TODO: add test that fails if `test` in conf.d/sdk.fish:80 errors (cf issue #28 et al.)