Merge branch 'dev'

This commit is contained in:
Raphael Reitzig 2019-11-05 04:42:40 +01:00
commit 813f1a1bd7
6 changed files with 64 additions and 23 deletions

View file

@ -1,5 +1,12 @@
root = true
[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 2
indent_size = 4
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false

View file

@ -21,4 +21,5 @@ script:
- ruby test/completion.rb
- fish test/wrapper.fish
- fish test/reinitialize.fish
- bash -c "sdk install crash 1.3.0; sdk uninstall crash 1.3.0"; fish test/10_zombies_new.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"

View file

@ -2,8 +2,8 @@
[![Build Status][travis-badge]][travis-link]
Makes command `sdk` from [SDKMAN!] available in fish.
Also provides auto-completion and adds binaries from installed SDKs to the PATH.
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.3.
@ -15,7 +15,10 @@ With [fisher] (install separately):
fisher add reitzig/sdkman-for-fish
```
_Note:_ Only compatible with fisher v3 upwards; v2 is no longer supported.
_Note:_
- Only compatible with fisher v3 upwards; v2 is no longer supported.
- You have to install [SDKMAN!] separately.
## Usage

View file

@ -15,11 +15,11 @@ if not test -f "$__fish_sdkman_init"
exit 0
end
# Hack for issue #19:
# Hack for issue #19:
# Create version of sdkman-init that doesn't export any environment variables.
# Refresh if sdkman-init changed.
if begin not test -f "$__fish_sdkman_noexport_init";
or env test "$__fish_sdkman_init" -nt "$__fish_sdkman_noexport_init"
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" \
@ -31,15 +31,15 @@ end
# 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 relevant environment variables (which might have changed)
# So, pipe relevant environment variables (which might have changed)
# through a file.
# 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;
bash -c "$argv[1];
echo -e \"\$?\" > $pipe;
env | grep -e '^SDKMAN_\|^PATH' >> $pipe;
env | grep -i -E \"^(`echo \${SDKMAN_CANDIDATES_CSV} | sed 's/,/|/g'`)_HOME\" >> $pipe;
echo \"SDKMAN_OFFLINE_MODE=\${SDKMAN_OFFLINE_MODE}\" >> $pipe" # it's not an environment variable!
@ -48,14 +48,14 @@ function __fish_sdkman_run_in_bash
set sdkStatus $bashDump[1]
set bashEnv $bashDump[2..-1]
# If SDKMAN! succeeded, copy relevant environment variables
# 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
@ -74,10 +74,11 @@ function __fish_sdkman_run_in_bash
return $sdkStatus
end
# If this is a subshell of a(n initialized) fish owned by the same user,
# no initialization necessary.
# 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)
set -e SDKMAN_DIR
__fish_sdkman_run_in_bash "source $__fish_sdkman_init"
end

View file

@ -1,9 +1,36 @@
# Guard: SDKMAN! needs to be installed
if not test -f "$__fish_sdkman_init"
exit 0
end
# Declare the sdk command for fish
function sdk -d "Manage SDKs"
__fish_sdkman_run_in_bash "source \"$__fish_sdkman_noexport_init\" && sdk $argv"
# Guard: SDKMAN! needs to be installed
if not test -f "$__fish_sdkman_init"
# Propose to install SDKMAN!
function read_confirm
while true
read -l -P "$argv[1] [y/N] " confirm
switch $confirm
case Y y
return 0
case '' N n
return 1
end
end
end
if read_confirm "You don't seem to have SDKMAN! installed. Install now?"
if not which curl > /dev/null
echo "curl required"
return 1
end
if not which bash > /dev/null
echo "bash required"
return 1
end
curl -s "https://get.sdkman.io" | bash | sed '/All done!/q'
echo "Please open a new terminal/shell to load SDKMAN!"
end
else
# Declare the _actual_ sdk command for fish
__fish_sdkman_run_in_bash "source \"$__fish_sdkman_noexport_init\" && sdk $argv"
end
end

View file

@ -16,10 +16,12 @@ begin
end
begin
set SDKMAN_DIR "/" # belongs to root, who hopefully doesn't run this
set -x SDKMAN_DIR "/" # belongs to root, who hopefully doesn't run this
set in_new_shell (fish -lc 'echo $SDKMAN_DIR')
if [ "$in_new_shell" != "$proper_value" ]
echo "SDKMAN_DIR reinitialized to $in_new_shell instead of $proper_value"
exit 1
end
end
# TODO: add test that fails if `test` in conf.d/sdk.fish:80 errors (cf issue #28 et al.)