From ba464925228b6e68ad47fc250c7c73036346312c Mon Sep 17 00:00:00 2001 From: Raphael Reitzig <4246780+reitzig@users.noreply.github.com> Date: Thu, 19 Jul 2018 00:02:31 +0200 Subject: [PATCH 1/4] Adds test case for issue #19. --- test/wrapper.fish | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/wrapper.fish b/test/wrapper.fish index 4979cf4..eca3dd5 100644 --- a/test/wrapper.fish +++ b/test/wrapper.fish @@ -8,7 +8,8 @@ set test_commands \ "sdk list java" \ "sdk update" \ "sdk use ant 1.9.9" \ - "sdk offline enable > /dev/null; sdk install ant foo" + "sdk offline enable > /dev/null; sdk install ant foo" \ + "sdk use ant 1.9.9 > /dev/null; sdk broadcast" set test_count (count $test_commands) set check_count (math "3 * $test_count") From 88c81dc4794c7acc92f2ce1127f15baa5302ace7 Mon Sep 17 00:00:00 2001 From: Raphael Reitzig <4246780+reitzig@users.noreply.github.com> Date: Thu, 19 Jul 2018 01:15:21 +0200 Subject: [PATCH 2/4] Implements a nasty hack for issue #19: mangle sdkman-init. --- conf.d/sdk.fish | 14 +++++++++++--- functions/sdk.fish | 8 ++++---- test/wrapper.fish | 5 +++-- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/conf.d/sdk.fish b/conf.d/sdk.fish index 71ee809..11450b1 100644 --- a/conf.d/sdk.fish +++ b/conf.d/sdk.fish @@ -7,13 +7,21 @@ # MIT License (MIT) # https://github.com/reitzig/sdkman-for-fish -set sdkman_init "$HOME/.sdkman/bin/sdkman-init.sh" +set __fish_sdkman_init "$HOME/.sdkman/bin/sdkman-init.sh" +set __fish_sdkman_noexport_init "$HOME/.config/fisherman/sdkman-for-fish/sdkman-noexport-init.sh" # Guard: SDKMAN! needs to be installed -if not test -f "$sdkman_init" +if not test -f "$__fish_sdkman_init" exit 0 end +# Hack for issue #19: Create version of sdkman-init that doesn't export +# any environment variables. +if not test -f "$__fish_sdkman_noexport_init" + sed -e 's/^\(\s*\).*\(export\|to_path\).*$/\1:/g' "$__fish_sdkman_init" \ + > $__fish_sdkman_noexport_init +end + # Runs the given command in bash, capturing some side effects # and repeating them on the current fish shell. # Returns the same status code as the given command. @@ -64,6 +72,6 @@ end # If this is a subshell of a(n initialized) fish, no initialization # necessary. Otherwise: if not set -q SDKMAN_DIR - __fish_sdkman_run_in_bash "source $sdkman_init" + __fish_sdkman_run_in_bash "source $__fish_sdkman_init" end diff --git a/functions/sdk.fish b/functions/sdk.fish index 5a65e50..0e0f8f0 100644 --- a/functions/sdk.fish +++ b/functions/sdk.fish @@ -1,11 +1,11 @@ -set sdkman_init "$HOME/.sdkman/bin/sdkman-init.sh" - # Guard: SDKMAN! needs to be installed -if not test -f "$sdkman_init" +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 $sdkman_init && sdk $argv" + __fish_sdkman_run_in_bash "source \"$__fish_sdkman_noexport_init\" && sdk $argv" + # __fish_sdkman_run_in_bash "source \"$__fish_sdkman_init\" && sdk $argv" + # --> issue #19 end \ No newline at end of file diff --git a/test/wrapper.fish b/test/wrapper.fish index eca3dd5..6ba684e 100644 --- a/test/wrapper.fish +++ b/test/wrapper.fish @@ -26,8 +26,9 @@ for sdk_cmd in $test_commands bash -c "source \"$sdk_init\" && $sdk_cmd > sout_bash; echo \"\$?\" > status_bash; echo "\$PATH" > path_bash" fish -c "$sdk_cmd > sout_fish; echo \"\$status\" > status_fish; echo "\$PATH" > path_fish" - # Adjust for different path syntax: replace spaces with colons - string join : (string split " " (cat path_fish)) > path_fish + # For nicer diffs: one entry per line, sorted + string split ":" (cat path_bash) | sort > path_bash + string split " " (cat path_fish) | sort > path_fish for out in sout status path if [ (checksum "$out"_bash) != (checksum "$out"_fish) ] From be5efd6aafc8f5e32ee96168eb0a36781b888367 Mon Sep 17 00:00:00 2001 From: Raphael Reitzig <4246780+reitzig@users.noreply.github.com> Date: Thu, 19 Jul 2018 01:31:13 +0200 Subject: [PATCH 3/4] Forgot that Travis wouldn't have the hack-assist folder. Relates to issue #19 --- conf.d/sdk.fish | 1 + 1 file changed, 1 insertion(+) diff --git a/conf.d/sdk.fish b/conf.d/sdk.fish index 11450b1..224709a 100644 --- a/conf.d/sdk.fish +++ b/conf.d/sdk.fish @@ -18,6 +18,7 @@ end # Hack for issue #19: Create version of sdkman-init that doesn't export # any environment variables. if not test -f "$__fish_sdkman_noexport_init" + mkdir -p (dirname $__fish_sdkman_noexport_init) sed -e 's/^\(\s*\).*\(export\|to_path\).*$/\1:/g' "$__fish_sdkman_init" \ > $__fish_sdkman_noexport_init end From 541a69e192ba018ff2399d9e696edcb43a811a64 Mon Sep 17 00:00:00 2001 From: Raphael Reitzig <4246780+reitzig@users.noreply.github.com> Date: Sat, 21 Jul 2018 16:24:21 +0200 Subject: [PATCH 4/4] Makes hack for issue #19 a litte more robust. Refresh the export-free sdkman-init whenever the original has changed. --- conf.d/sdk.fish | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/conf.d/sdk.fish b/conf.d/sdk.fish index 224709a..af1ee5d 100644 --- a/conf.d/sdk.fish +++ b/conf.d/sdk.fish @@ -15,9 +15,12 @@ if not test -f "$__fish_sdkman_init" exit 0 end -# Hack for issue #19: Create version of sdkman-init that doesn't export -# any environment variables. -if not test -f "$__fish_sdkman_noexport_init" +# Hack for issue #19: +# Create version of sdkman-init that doesn't export any environment variables. +# Refresh if sdkman-init changed. +if begin not test -f "$__fish_sdkman_noexport_init"; + or env test "$__fish_sdkman_init" -nt "$__fish_sdkman_noexport_init" + end mkdir -p (dirname $__fish_sdkman_noexport_init) sed -e 's/^\(\s*\).*\(export\|to_path\).*$/\1:/g' "$__fish_sdkman_init" \ > $__fish_sdkman_noexport_init