From e01e9a4bea32ac879584bba9fe0b793c31fceb91 Mon Sep 17 00:00:00 2001 From: Raphael Reitzig <4246780+reitzig@users.noreply.github.com> Date: Wed, 18 Jul 2018 22:05:57 +0200 Subject: [PATCH] Refactoring: bash calling in its own function. Also: - Fixes Travis build reg. bf13d2f. - Wrapper test now cleans up after itself. --- .travis.yml | 2 +- functions/sdk.fish | 13 ++++++++++--- test/wrapper.fish | 2 ++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index e985a02..eb34a4b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,7 @@ install: - mkdir -p "${HOME}"/.config/fish/{completions,conf.d,functions} - cp completions/* "${HOME}"/.config/fish/completions/ - cp conf.d/* "${HOME}"/.config/fish/conf.d/ - #- cp functions/* "${HOME}"/.config/fish/functions/ + - cp functions/* "${HOME}"/.config/fish/functions/ jobs: include: diff --git a/functions/sdk.fish b/functions/sdk.fish index 0226a81..0e5dead 100644 --- a/functions/sdk.fish +++ b/functions/sdk.fish @@ -5,14 +5,16 @@ if not test -f "$sdkman_init" exit 0 end -# Declare the sdk command for fish -function sdk -d "Manage SDKs" +# 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. +function __fish_sdkman_run_in_bash # We need to leave stdin and stdout of sdk free for user interaction. # So, pipe PATH (which might have changed) through a file. # Now, getting the exit code of sdk itself is a hassle so pipe it as well. # TODO: Can somebody get this to work without the overhead of a file? set pipe (mktemp) - bash -c "source $sdkman_init && sdk $argv; echo -e \"\$PATH\n\$?\" > $pipe" + bash -c "$argv[1]; echo -e \"\$PATH\n\$?\" > $pipe" set bashDump (cat $pipe; rm $pipe) set bashPath $bashDump[1] @@ -24,4 +26,9 @@ function sdk -d "Manage SDKs" end return $sdkStatus +end + +# Declare the sdk command for fish +function sdk -d "Manage SDKs" + __fish_sdkman_run_in_bash "source $sdkman_init && sdk $argv" end \ No newline at end of file diff --git a/test/wrapper.fish b/test/wrapper.fish index 630df77..c61c1af 100644 --- a/test/wrapper.fish +++ b/test/wrapper.fish @@ -39,6 +39,8 @@ for sdk_cmd in $test_commands echo "" end +rm {sout, status, path}_{bash, fish} + echo "Ran $test_count commands with 3 checks each." echo "$failures/$check_count checks failed." exit (math $failures != 0) \ No newline at end of file