mirror of
https://github.com/ethauvin/sdkman-for-fish.git
synced 2025-04-27 21:58:11 -07:00
Refactoring: Adhere better to conventions.
Define function sdk in functions/sdk.fish and perform init in conf.d/sdk.fish.
This commit is contained in:
parent
b6a1469ed5
commit
bf13d2fee1
2 changed files with 41 additions and 31 deletions
|
@ -9,8 +9,11 @@
|
||||||
|
|
||||||
set sdkman_init "$HOME/.sdkman/bin/sdkman-init.sh"
|
set sdkman_init "$HOME/.sdkman/bin/sdkman-init.sh"
|
||||||
|
|
||||||
# Don't do anything if SDKMAN! isn't installed, because that would be silly
|
# Guard: SDKMAN! needs to be installed
|
||||||
if test -f "$sdkman_init"
|
if not test -f "$sdkman_init"
|
||||||
|
exit 0
|
||||||
|
end
|
||||||
|
|
||||||
# Add binaries from installed SDKs to PATH, if necessary
|
# Add binaries from installed SDKs to PATH, if necessary
|
||||||
switch "$PATH"
|
switch "$PATH"
|
||||||
case "*$HOME/.sdkman/candidates/*"
|
case "*$HOME/.sdkman/candidates/*"
|
||||||
|
@ -22,24 +25,4 @@ if test -f "$sdkman_init"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Declare the sdk command for fish
|
|
||||||
function sdk -d "Manage SDKs"
|
|
||||||
# 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"
|
|
||||||
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
|
|
||||||
end
|
|
||||||
|
|
27
functions/sdk.fish
Normal file
27
functions/sdk.fish
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
set sdkman_init "$HOME/.sdkman/bin/sdkman-init.sh"
|
||||||
|
|
||||||
|
# Guard: SDKMAN! needs to be installed
|
||||||
|
if not test -f "$sdkman_init"
|
||||||
|
exit 0
|
||||||
|
end
|
||||||
|
|
||||||
|
# Declare the sdk command for fish
|
||||||
|
function sdk -d "Manage SDKs"
|
||||||
|
# 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"
|
||||||
|
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
|
Loading…
Add table
Add a link
Reference in a new issue