Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
reitzig committed Nov 6, 2019
2 parents 83711b1 + ed6039e commit c9fd8d5
Show file tree
Hide file tree
Showing 9 changed files with 181 additions and 78 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@ indent_size = 4
trim_trailing_whitespace = true
insert_final_newline = true

[*.{yaml,yml}]
indent_size = 2

[*.md]
trim_trailing_whitespace = false
43 changes: 34 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,37 @@
env:
- FISH=release-2
- FISH=release-3
matrix:
include:
- dist: bionic
env: FISH=2
addons:
apt:
sources:
- sourceline: "ppa:fish-shell/release-2"
packages:
- fish
- dist: bionic
env: FISH=3
addons:
apt:
sources:
- sourceline: "ppa:fish-shell/release-3"
packages:
- fish
- os: osx
env: FISH=2
addons:
homebrew:
packages:
- 'test/Homebrew-Formula-fish-2.7.1.rb'
update: true # TODO: build should be green without, but isn't
- os: osx
env: FISH=3
addons:
homebrew:
packages:
- fish # --> latest, i.e. >=3.0.2
update: true # TODO: build should be green without, but isn't

sudo: required
before_install:
- sudo add-apt-repository -y ppa:fish-shell/${FISH}
- sudo apt-get update
- sudo apt-get -y install fish
- curl -s "https://get.sdkman.io" | bash
- bash test/prepare_tests.sh

Expand All @@ -21,5 +46,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"
- fish -c "sdk install crash 1.3.0; and sdk uninstall crash 1.3.0" > /dev/null && fish test/check_for_path_zombies.fish
- bash test/remove_sdkman.sh > /dev/null && fish -c "echo 'y' | sdk" > /dev/null && fish -c "sdk version"
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
Makes command `sdk` from [SDKMAN!] usable from fish, including auto-completion.
Also adds binaries from installed SDKs to the PATH.

Tested with fish 2.7.1 and 3.0.2, and SDKMAN! 5.7.4.
Version 1.4.0 tested with

- fish 2.7.1 and 3.0.2, and
- SDKMAN! 5.7.4, on
- Ubuntu 18.04 LTS and macOS 10.13.

## Install

Expand Down
124 changes: 62 additions & 62 deletions completions/sdk.fish
Original file line number Diff line number Diff line change
Expand Up @@ -6,76 +6,76 @@

# Guard: SDKMAN! needs to be installed
if not test -f "$HOME/.sdkman/bin/sdkman-init.sh"
exit 0
exit 0
end

# # # # # #
# Completion trigger predicates
# # # # # #

# 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

# # # # # #
# Data collectors
# # # # # #

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

# # # # # #
Expand All @@ -87,96 +87,96 @@ 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
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
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
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
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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
8 changes: 4 additions & 4 deletions conf.d/sdk.fish
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ if begin not test -f "$__fish_sdkman_noexport_init";
or env test "$__fish_sdkman_init" -nt "$__fish_sdkman_noexport_init"
end
mkdir -p (dirname $__fish_sdkman_noexport_init)
sed -e 's/^\(\s*\).*\(export\|to_path\).*$/\1:/g' "$__fish_sdkman_init" \
> $__fish_sdkman_noexport_init
sed -E -e 's/^(\s*).*(export|to_path).*$/\1:/g' "$__fish_sdkman_init" \
> "$__fish_sdkman_noexport_init"
end

# Runs the given command in bash, capturing some side effects
Expand Down Expand Up @@ -66,7 +66,7 @@ function __fish_sdkman_run_in_bash
if test -n value
set -gx $var $value
# Note: This makes SDKMAN_OFFLINE_MODE an environment variable.
# That gives it the behavariour we _want_!
# That gives it the behaviour we _want_!
end
end
end
Expand All @@ -77,7 +77,7 @@ end
# If this is a subshell of a(n initialized) fish owned by the same user,
# no initialization necessary.
# Otherwise:
if not set -q SDKMAN_DIR; or test (stat -c "%U" $SDKMAN_DIR) != (whoami)
if not set -q SDKMAN_DIR; or test (ls -ld "$SDKMAN_DIR" | awk '{print $3}') != (whoami)
set -e SDKMAN_DIR
__fish_sdkman_run_in_bash "source $__fish_sdkman_init"
end
Expand Down
Loading

0 comments on commit c9fd8d5

Please sign in to comment.