Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions init.fish
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,27 @@ if type -q fenv
set -g sdkman_prefix $SDKMAN_DIR

fenv "source $sdkman_prefix/bin/sdkman-init.sh"

if grep -q "^sdkman_auto_env=true" "$sdkman_prefix/etc/config"
function __omf_sdk_sdkman_auto_env --on-variable PWD

# chdir from current SDKMAN_ENV dirtree outside
# or
# chdir into dir with .sdkmanrc that doesn't match the current SDKMAN_ENV root
if begin; test -n $SDKMAN_ENV && not string match -q "$SDKMAN_ENV/**" "$PWD/"; end \
|| begin; test "$SDKMAN_OLD_PWD" != "$PWD" && test "$SDKMAN_ENV" != "$PWD" && test -f ".sdkmanrc"; end

# runs SDKMAN's chdir hook, results in `sdk env clear` (if there was a previous SDKMAN_ENV) and `sdk env` (if there is a new .sdkmanrc)
fenv "source $sdkman_prefix/bin/sdkman-init.sh && export SDKMAN_ENV"

# there was `sdk env clear` without `sdk env`
if not test -f ".sdkmanrc"
# unset SDKMAN_ENV as fenv can't currently unset variables
set -eg SDKMAN_ENV
end
end

set -gx SDKMAN_OLD_PWD "$PWD"
end
end
end