mirror of
https://github.com/ethauvin/sdkman-for-fish.git
synced 2025-04-25 13:27:10 -07:00
issue #29: Replace stat
with something more portable.
cf. https://unix.stackexchange.com/a/7732/17409
This commit is contained in:
parent
b1887e4170
commit
12f7d3de77
1 changed files with 10 additions and 10 deletions
|
@ -15,11 +15,11 @@ if not test -f "$__fish_sdkman_init"
|
||||||
exit 0
|
exit 0
|
||||||
end
|
end
|
||||||
|
|
||||||
# Hack for issue #19:
|
# Hack for issue #19:
|
||||||
# Create version of sdkman-init that doesn't export any environment variables.
|
# Create version of sdkman-init that doesn't export any environment variables.
|
||||||
# Refresh if sdkman-init changed.
|
# Refresh if sdkman-init changed.
|
||||||
if begin not test -f "$__fish_sdkman_noexport_init";
|
if begin not test -f "$__fish_sdkman_noexport_init";
|
||||||
or env test "$__fish_sdkman_init" -nt "$__fish_sdkman_noexport_init"
|
or env test "$__fish_sdkman_init" -nt "$__fish_sdkman_noexport_init"
|
||||||
end
|
end
|
||||||
mkdir -p (dirname $__fish_sdkman_noexport_init)
|
mkdir -p (dirname $__fish_sdkman_noexport_init)
|
||||||
sed -e 's/^\(\s*\).*\(export\|to_path\).*$/\1:/g' "$__fish_sdkman_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.
|
# Returns the same status code as the given command.
|
||||||
function __fish_sdkman_run_in_bash
|
function __fish_sdkman_run_in_bash
|
||||||
# We need to leave stdin and stdout of sdk free for user interaction.
|
# 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.
|
# through a file.
|
||||||
# But since now getting the exit code of sdk itself is a hassle,
|
# But since now getting the exit code of sdk itself is a hassle,
|
||||||
# pipe it as well.
|
# pipe it as well.
|
||||||
#
|
#
|
||||||
# TODO: Can somebody get this to work without the overhead of a file?
|
# TODO: Can somebody get this to work without the overhead of a file?
|
||||||
set pipe (mktemp)
|
set pipe (mktemp)
|
||||||
bash -c "$argv[1];
|
bash -c "$argv[1];
|
||||||
echo -e \"\$?\" > $pipe;
|
echo -e \"\$?\" > $pipe;
|
||||||
env | grep -e '^SDKMAN_\|^PATH' >> $pipe;
|
env | grep -e '^SDKMAN_\|^PATH' >> $pipe;
|
||||||
env | grep -i -E \"^(`echo \${SDKMAN_CANDIDATES_CSV} | sed 's/,/|/g'`)_HOME\" >> $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!
|
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 sdkStatus $bashDump[1]
|
||||||
set bashEnv $bashDump[2..-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)
|
# to the current shell (they might have changed)
|
||||||
if [ $sdkStatus = 0 ]
|
if [ $sdkStatus = 0 ]
|
||||||
for line in $bashEnv
|
for line in $bashEnv
|
||||||
set parts (string split "=" $line)
|
set parts (string split "=" $line)
|
||||||
set var $parts[1]
|
set var $parts[1]
|
||||||
set value (string join "=" $parts[2..-1])
|
set value (string join "=" $parts[2..-1])
|
||||||
|
|
||||||
switch "$var"
|
switch "$var"
|
||||||
case "PATH"
|
case "PATH"
|
||||||
# Special treatment: need fish list instead
|
# Special treatment: need fish list instead
|
||||||
|
@ -74,10 +74,10 @@ function __fish_sdkman_run_in_bash
|
||||||
return $sdkStatus
|
return $sdkStatus
|
||||||
end
|
end
|
||||||
|
|
||||||
# If this is a subshell of a(n initialized) fish owned by the same user,
|
# If this is a subshell of a(n initialized) fish owned by the same user,
|
||||||
# no initialization necessary.
|
# no initialization necessary.
|
||||||
# Otherwise:
|
# 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)
|
||||||
__fish_sdkman_run_in_bash "source $__fish_sdkman_init"
|
__fish_sdkman_run_in_bash "source $__fish_sdkman_init"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue