Improves behaviour if SDKMAN! is not installed.

Instead of creating all functions and completions and
_add_ one to handle the special case, just don't define
all the things.
This commit is contained in:
Raphael Reitzig 2018-07-18 21:04:13 +02:00
parent 74924f8961
commit d276be6768

View file

@ -4,23 +4,17 @@
# MIT License (MIT)
# https://github.com/reitzig/sdkman-for-fish
# Guard: SDKMAN! needs to be installed
if not test -f "$HOME/.sdkman/bin/sdkman-init.sh"
exit 0
end
# # # # # #
# Completion trigger predicates
# # # # # #
function __fish_sdkman_sdk_is_missing
if test -f "$HOME/.sdkman/bin/sdkman-init.sh"
return 1
else
return 0
end
end
function __fish_sdkman_no_command --description 'Test if there is no command'
if __fish_sdkman_sdk_is_missing
return 1 # Suppress completion
end
# Test if there is no command
function __fish_sdkman_no_command
set cmd (commandline -opc)
if [ (count $cmd) -eq 1 ]
@ -29,11 +23,8 @@ function __fish_sdkman_no_command --description 'Test if there is no command'
return 1
end
function __fish_sdkman_using_command --description 'Test if the main command matches one of the parameters'
if __fish_sdkman_sdk_is_missing
return 1 # Suppress completion
end
# Test if the main command matches one of the parameters
function __fish_sdkman_using_command
set cmd (commandline -opc)
if [ (count $cmd) -eq 2 ]
@ -45,10 +36,6 @@ function __fish_sdkman_using_command --description 'Test if the main command mat
end
function __fish_sdkman_specifying_candidate
if __fish_sdkman_sdk_is_missing
return 1 # Suppress completion
end
set cmd (commandline -opc)
if [ (count $cmd) -eq 3 ] # currently, sdk does not support multiple versions
@ -95,9 +82,6 @@ end
# Completion specification
# # # # # #
# Suppress any default completion if sdkman is not installed
complete -c sdk -f -n '__fish_sdkman_sdk_is_missing'
# install
complete -c sdk -f -n '__fish_sdkman_no_command' \
-a 'i install' \