mirror of
https://github.com/ethauvin/sdkman-for-fish.git
synced 2025-04-25 05:17:11 -07:00
issue #29: Avoid GNU-specific find
.
This commit is contained in:
parent
060169f5da
commit
7faecfd154
2 changed files with 64 additions and 64 deletions
|
@ -47,5 +47,5 @@ script:
|
|||
- ruby test/completion.rb
|
||||
- fish test/wrapper.fish
|
||||
- fish test/reinitialize.fish
|
||||
- bash -c "source ${HOME}/.sdkman/bin/sdkman-init.sh && sdk install crash 1.3.0 && sdk uninstall crash 1.3.0" && fish test/10_zombies_new.fish
|
||||
- bash -c "rm -rf ~/.sdkman && sed -i 's/^.*\(sdkman\|SDKMAN\).*$//g' ~/.bashrc && echo 'SDKMAN uninstalled'" && fish -c "echo 'y' | sdk" && fish -c "sdk version"
|
||||
- bash -c "source \"${HOME}/.sdkman/bin/sdkman-init.sh\" && sdk install crash 1.3.0 && sdk uninstall crash 1.3.0" && fish test/10_zombies_new.fish
|
||||
- bash -c "rm -rf \"${HOME}/.sdkman\" && sed -i 's/^.*\(sdkman\|SDKMAN\).*$//g' \"${HOME}/.bashrc\" && echo 'SDKMAN uninstalled'" && fish -c "echo 'y' | sdk" && fish -c "sdk version"
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
# Guard: SDKMAN! needs to be installed
|
||||
if not test -f "$HOME/.sdkman/bin/sdkman-init.sh"
|
||||
exit 0
|
||||
exit 0
|
||||
end
|
||||
|
||||
# # # # # #
|
||||
|
@ -14,45 +14,45 @@ end
|
|||
# # # # # #
|
||||
|
||||
# Test if there is no command
|
||||
function __fish_sdkman_no_command
|
||||
set cmd (commandline -opc)
|
||||
function __fish_sdkman_no_command
|
||||
set cmd (commandline -opc)
|
||||
|
||||
if [ (count $cmd) -eq 1 ]
|
||||
return 0
|
||||
end
|
||||
return 1
|
||||
if [ (count $cmd) -eq 1 ]
|
||||
return 0
|
||||
end
|
||||
return 1
|
||||
end
|
||||
|
||||
# Test if the main command matches one of the parameters
|
||||
function __fish_sdkman_using_command
|
||||
set cmd (commandline -opc)
|
||||
set cmd (commandline -opc)
|
||||
|
||||
if [ (count $cmd) -eq 2 ]
|
||||
if contains $cmd[2] $argv
|
||||
return 0
|
||||
if [ (count $cmd) -eq 2 ]
|
||||
if contains $cmd[2] $argv
|
||||
return 0
|
||||
end
|
||||
end
|
||||
end
|
||||
return 1
|
||||
return 1
|
||||
end
|
||||
|
||||
function __fish_sdkman_specifying_candidate
|
||||
set cmd (commandline -opc)
|
||||
set cmd (commandline -opc)
|
||||
|
||||
if [ (count $cmd) -eq 3 ] # currently, sdk does not support multiple versions
|
||||
if contains $cmd[2] $argv ]
|
||||
return 0
|
||||
if [ (count $cmd) -eq 3 ] # currently, sdk does not support multiple versions
|
||||
if contains $cmd[2] $argv ]
|
||||
return 0
|
||||
end
|
||||
end
|
||||
end
|
||||
return 1
|
||||
return 1
|
||||
end
|
||||
|
||||
function __fish_sdkman_command_has_enough_parameters
|
||||
set cmd (commandline -opc)
|
||||
|
||||
if [ (count $cmd) -ge (math $argv[1] + 2) ]; and contains $cmd[2] $argv[2..-1]
|
||||
return 0
|
||||
end
|
||||
return 1
|
||||
set cmd (commandline -opc)
|
||||
|
||||
if [ (count $cmd) -ge (math $argv[1] + 2) ]; and contains $cmd[2] $argv[2..-1]
|
||||
return 0
|
||||
end
|
||||
return 1
|
||||
end
|
||||
|
||||
# # # # # #
|
||||
|
@ -60,22 +60,22 @@ end
|
|||
# # # # # #
|
||||
|
||||
function __fish_sdkman_candidates
|
||||
cat "$HOME"/.sdkman/var/candidates | tr ',' '\n'
|
||||
cat "$HOME"/.sdkman/var/candidates | tr ',' '\n'
|
||||
end
|
||||
|
||||
function __fish_sdkman_candidates_with_versions
|
||||
set regexpHome (string replace -a '/' '\\/' "$HOME/")
|
||||
find "$HOME"/.sdkman/candidates/ -name '*current*' -printf "%h\n" \
|
||||
| sed -e "s/$regexpHome//" \
|
||||
| cut -d '/' -f 3 \
|
||||
| sort -u
|
||||
set regexpHome (string replace -a '/' '\\/' "$HOME/")
|
||||
|
||||
find "$HOME"/.sdkman/candidates/ -mindepth 2 -maxdepth 2 -name '*current' \
|
||||
| awk -F '/' '{ print $(NF-1) }' \
|
||||
| sort -u
|
||||
end
|
||||
|
||||
function __fish_sdkman_installed_versions
|
||||
set cmd (commandline -opc)
|
||||
if [ -d "$HOME"/.sdkman/candidates/$cmd[3]/current ]
|
||||
ls -v1 "$HOME"/.sdkman/candidates/$cmd[3] | grep -v current
|
||||
end
|
||||
set cmd (commandline -opc)
|
||||
if [ -d "$HOME"/.sdkman/candidates/$cmd[3]/current ]
|
||||
ls -v1 "$HOME"/.sdkman/candidates/$cmd[3] | grep -v current
|
||||
end
|
||||
end
|
||||
|
||||
# # # # # #
|
||||
|
@ -87,26 +87,26 @@ complete -c sdk -f -n '__fish_sdkman_no_command' \
|
|||
-a 'i install' \
|
||||
-d 'Install new version'
|
||||
complete -c sdk -f -n '__fish_sdkman_using_command i install' \
|
||||
-a "(__fish_sdkman_candidates)"
|
||||
-a "(__fish_sdkman_candidates)"
|
||||
complete -c sdk -f -n '__fish_sdkman_specifying_candidate i install' \
|
||||
# TODO complete available versions --> #4
|
||||
-a 'a.b.c' \
|
||||
-d "version list unavailable"
|
||||
-d "version list unavailable"
|
||||
complete -c sdk -f -n '__fish_sdkman_specifying_candidate i install' \
|
||||
-a 'x.y.z' \
|
||||
-d "Add your own; specify path!"
|
||||
-d "Add your own; specify path!"
|
||||
# Implicit: complete files as fourth parameter
|
||||
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 3 i install'
|
||||
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 3 i install'
|
||||
# block
|
||||
|
||||
# uninstall
|
||||
complete -c sdk -f -n '__fish_sdkman_no_command' \
|
||||
-a 'rm uninstall' -d 'Uninstall version'
|
||||
complete -c sdk -f -n '__fish_sdkman_using_command rm uninstall' \
|
||||
-a "(__fish_sdkman_candidates_with_versions)"
|
||||
-a "(__fish_sdkman_candidates_with_versions)"
|
||||
complete -c sdk -f -n '__fish_sdkman_specifying_candidate rm uninstall' \
|
||||
-a "(__fish_sdkman_installed_versions)"
|
||||
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 2 rm uninstall'
|
||||
-a "(__fish_sdkman_installed_versions)"
|
||||
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 2 rm uninstall'
|
||||
# block
|
||||
|
||||
# list
|
||||
|
@ -114,19 +114,19 @@ complete -c sdk -f -n '__fish_sdkman_no_command' \
|
|||
-a 'ls list' \
|
||||
-d 'List versions'
|
||||
complete -c sdk -f -n '__fish_sdkman_using_command ls list' \
|
||||
-a "(__fish_sdkman_candidates)"
|
||||
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 1 ls list'
|
||||
# block
|
||||
-a "(__fish_sdkman_candidates)"
|
||||
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 1 ls list'
|
||||
# block
|
||||
|
||||
# use
|
||||
complete -c sdk -f -n '__fish_sdkman_no_command' \
|
||||
-a 'u use' \
|
||||
-d 'Use specific version'
|
||||
complete -c sdk -f -n '__fish_sdkman_using_command u use' \
|
||||
-a "(__fish_sdkman_candidates_with_versions)"
|
||||
-a "(__fish_sdkman_candidates_with_versions)"
|
||||
complete -c sdk -f -n '__fish_sdkman_specifying_candidate u use' \
|
||||
-a "(__fish_sdkman_installed_versions)"
|
||||
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 2 u use'
|
||||
-a "(__fish_sdkman_installed_versions)"
|
||||
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 2 u use'
|
||||
# block
|
||||
|
||||
# default
|
||||
|
@ -134,10 +134,10 @@ complete -c sdk -f -n '__fish_sdkman_no_command' \
|
|||
-a 'd default' \
|
||||
-d 'Set default version'
|
||||
complete -c sdk -f -n '__fish_sdkman_using_command d default' \
|
||||
-a "(__fish_sdkman_candidates_with_versions)"
|
||||
-a "(__fish_sdkman_candidates_with_versions)"
|
||||
complete -c sdk -f -n '__fish_sdkman_specifying_candidate d default' \
|
||||
-a "(__fish_sdkman_installed_versions)"
|
||||
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 2 d default'
|
||||
-a "(__fish_sdkman_installed_versions)"
|
||||
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 2 d default'
|
||||
# block
|
||||
|
||||
# current
|
||||
|
@ -145,8 +145,8 @@ complete -c sdk -f -n '__fish_sdkman_no_command' \
|
|||
-a 'c current' \
|
||||
-d 'Display current version'
|
||||
complete -c sdk -f -n '__fish_sdkman_using_command c current' \
|
||||
-a "(__fish_sdkman_candidates)"
|
||||
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 1 c current'
|
||||
-a "(__fish_sdkman_candidates)"
|
||||
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 1 c current'
|
||||
# block
|
||||
|
||||
# upgrade
|
||||
|
@ -154,29 +154,29 @@ complete -c sdk -f -n '__fish_sdkman_no_command' \
|
|||
-a 'ug upgrade' \
|
||||
-d 'Display what is outdated'
|
||||
complete -c sdk -f -n '__fish_sdkman_using_command ug upgrade' \
|
||||
-a "(__fish_sdkman_candidates_with_versions)"
|
||||
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 1 ug upgrade'
|
||||
-a "(__fish_sdkman_candidates_with_versions)"
|
||||
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 1 ug upgrade'
|
||||
# block
|
||||
|
||||
# version
|
||||
complete -c sdk -f -n '__fish_sdkman_no_command' \
|
||||
-a 'v version' \
|
||||
-d 'Display version'
|
||||
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 0 v version'
|
||||
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 0 v version'
|
||||
# block
|
||||
|
||||
# broadcast
|
||||
complete -c sdk -f -n '__fish_sdkman_no_command' \
|
||||
-a 'b broadcast' \
|
||||
-d 'Display broadcast message'
|
||||
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 0 b broadcast'
|
||||
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 0 b broadcast'
|
||||
# block
|
||||
|
||||
# help
|
||||
complete -c sdk -f -n '__fish_sdkman_no_command' \
|
||||
-a 'h help' \
|
||||
-d 'Display help message'
|
||||
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 0 h help'
|
||||
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 0 h help'
|
||||
# block
|
||||
|
||||
# offline
|
||||
|
@ -189,7 +189,7 @@ complete -c sdk -f -n '__fish_sdkman_using_command offline' \
|
|||
complete -c sdk -f -n '__fish_sdkman_using_command offline' \
|
||||
-a 'disable' \
|
||||
-d 'Turn on all features'
|
||||
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 1 offline'
|
||||
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 1 offline'
|
||||
# block
|
||||
|
||||
# selfupdate
|
||||
|
@ -199,14 +199,14 @@ complete -c sdk -f -n '__fish_sdkman_no_command' \
|
|||
complete -c sdk -f -n '__fish_sdkman_using_command selfupdate' \
|
||||
-a 'force' \
|
||||
-d 'Force re-install of current version'
|
||||
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 1 selfupdate'
|
||||
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 1 selfupdate'
|
||||
# block
|
||||
|
||||
# update
|
||||
complete -c sdk -f -n '__fish_sdkman_no_command' \
|
||||
-a 'update' \
|
||||
-d 'Reload the candidate list'
|
||||
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 0 update'
|
||||
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 0 update'
|
||||
# block
|
||||
|
||||
# flush
|
||||
|
@ -222,5 +222,5 @@ complete -c sdk -f -n '__fish_sdkman_using_command flush' \
|
|||
complete -c sdk -f -n '__fish_sdkman_using_command flush' \
|
||||
-a 'temp' \
|
||||
-d 'Clear installation prep folder'
|
||||
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 1 flush'
|
||||
complete -c sdk -f -n '__fish_sdkman_command_has_enough_parameters 1 flush'
|
||||
# block
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue