mirror of
https://github.com/ethauvin/sdkman-for-fish.git
synced 2025-04-25 13:27:10 -07:00
Offline mode now works.
- Initialization now delegates do sdkman-init.sh - bash-runner now catches all SDKMAN_* environment variables. Fixes issue #17 Unearthes issue #19
This commit is contained in:
parent
e01e9a4bea
commit
597945453d
3 changed files with 52 additions and 33 deletions
|
@ -14,15 +14,56 @@ if not test -f "$sdkman_init"
|
||||||
exit 0
|
exit 0
|
||||||
end
|
end
|
||||||
|
|
||||||
# Add binaries from installed SDKs to PATH, if necessary
|
# Runs the given command in bash, capturing some side effects
|
||||||
switch "$PATH"
|
# and repeating them on the current fish shell.
|
||||||
case "*$HOME/.sdkman/candidates/*"
|
# Returns the same status code as the given command.
|
||||||
# This is a subshell, SDKMAN! binaries already in path.
|
function __fish_sdkman_run_in_bash
|
||||||
case '*'
|
# We need to leave stdin and stdout of sdk free for user interaction.
|
||||||
# No SDKMAN! in PATH yet, so add candidate binaries
|
# So, pipe relevant environment variables (which might have changed)
|
||||||
for ITEM in $HOME/.sdkman/candidates/*/current ;
|
# through a file.
|
||||||
set -gx PATH $PATH $ITEM/bin
|
# But since now getting the exit code of sdk itself is a hassle,
|
||||||
|
# pipe it as well.
|
||||||
|
#
|
||||||
|
# TODO: Can somebody get this to work without the overhead of a file?
|
||||||
|
set pipe (mktemp)
|
||||||
|
bash -c "$argv[1];
|
||||||
|
echo -e \"\$?\" > $pipe;
|
||||||
|
env | grep -e '^SDKMAN_\|^PATH' >> $pipe;
|
||||||
|
echo \"SDKMAN_OFFLINE_MODE=\${SDKMAN_OFFLINE_MODE}\" >> $pipe" # it's not an environment variable!
|
||||||
|
set bashDump (cat $pipe; rm $pipe)
|
||||||
|
|
||||||
|
set sdkStatus $bashDump[1]
|
||||||
|
set bashEnv $bashDump[2..-1]
|
||||||
|
|
||||||
|
# If SDKMAN! succeeded, copy relevant environment variables
|
||||||
|
# to the current shell (they might have changed)
|
||||||
|
if [ $sdkStatus = 0 ]
|
||||||
|
for line in $bashEnv
|
||||||
|
set parts (string split "=" $line)
|
||||||
|
set var $parts[1]
|
||||||
|
set value (string join "=" $parts[2..-1])
|
||||||
|
|
||||||
|
switch "$var"
|
||||||
|
case "PATH"
|
||||||
|
# Special treatment: need fish list instead
|
||||||
|
# of colon-separated list.
|
||||||
|
set value (string split : "$value")
|
||||||
|
end
|
||||||
|
|
||||||
|
if test -n value
|
||||||
|
set -gx $var $value
|
||||||
|
# Note: This makes SDKMAN_OFFLINE_MODE an environment variable.
|
||||||
|
# That gives it the behavariour we _want_!
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return $sdkStatus
|
||||||
end
|
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"
|
||||||
|
end
|
||||||
|
|
||||||
|
|
|
@ -5,29 +5,6 @@ if not test -f "$sdkman_init"
|
||||||
exit 0
|
exit 0
|
||||||
end
|
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.
|
|
||||||
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 "$argv[1]; echo -e \"\$PATH\n\$?\" > $pipe"
|
|
||||||
set bashDump (cat $pipe; rm $pipe)
|
|
||||||
|
|
||||||
set bashPath $bashDump[1]
|
|
||||||
set sdkStatus $bashDump[2]
|
|
||||||
# If SDKMAN! succeeded, copy PATH here (might have changed)
|
|
||||||
if [ $sdkStatus = 0 ]
|
|
||||||
set newPath (string split : "$bashPath")
|
|
||||||
set -gx PATH $newPath
|
|
||||||
end
|
|
||||||
|
|
||||||
return $sdkStatus
|
|
||||||
end
|
|
||||||
|
|
||||||
# Declare the sdk command for fish
|
# Declare the sdk command for fish
|
||||||
function sdk -d "Manage SDKs"
|
function sdk -d "Manage SDKs"
|
||||||
__fish_sdkman_run_in_bash "source $sdkman_init && sdk $argv"
|
__fish_sdkman_run_in_bash "source $sdkman_init && sdk $argv"
|
||||||
|
|
|
@ -7,7 +7,8 @@ set test_commands \
|
||||||
"sdk version" \
|
"sdk version" \
|
||||||
"sdk list java" \
|
"sdk list java" \
|
||||||
"sdk update" \
|
"sdk update" \
|
||||||
"sdk use ant 1.9.9"
|
"sdk use ant 1.9.9" \
|
||||||
|
"sdk offline enable > /dev/null; sdk install ant foo"
|
||||||
set test_count (count $test_commands)
|
set test_count (count $test_commands)
|
||||||
set check_count (math "3 * $test_count")
|
set check_count (math "3 * $test_count")
|
||||||
|
|
||||||
|
@ -39,7 +40,7 @@ for sdk_cmd in $test_commands
|
||||||
echo ""
|
echo ""
|
||||||
end
|
end
|
||||||
|
|
||||||
rm {sout, status, path}_{bash, fish}
|
rm {sout,status,path}_{bash,fish}
|
||||||
|
|
||||||
echo "Ran $test_count commands with 3 checks each."
|
echo "Ran $test_count commands with 3 checks each."
|
||||||
echo "$failures/$check_count checks failed."
|
echo "$failures/$check_count checks failed."
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue