Created
May 30, 2020 23:40
-
-
Save Amar1729/294c6e310b191405bf8fceb72e96b399 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# sdkman recommands settings SDKMAN_DIR and sourcing sdkman-init.sh | |
# this can really slow down shell startup, so here's my attempt to lazy-load sdk() | |
# | |
# This snippet lives in my ~/.profile but generally could live in any zsh-related startup file. | |
# | |
# the logic of this custom sdk is kind of odd, but it basically checks if the current | |
# definition of sdk() is too short (less than 10 lines). If so, it tries to source | |
# the init script and then pass through all the arguments to the real sdk function. | |
export SDKMAN_DIR="$HOME/.sdkman" | |
# too slow! | |
# [[ -s "$SDKMAN_DIR/bin/sdkman-init.sh" ]] && source "$SDKMAN_DIR/bin/sdkman-init.sh" | |
# do this instead: | |
sdk () { | |
# "metaprogramming" lol - source init if sdk currently looks like this sdk function | |
if [[ "$(which sdk | wc -l)" -le 10 ]]; then | |
unset -f sdk | |
source "$SDKMAN_DIR/bin/sdkman-init.sh" | |
fi | |
sdk "$@" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Except for nvm, you can't use global installed packages like
npm
,npx
and so on before actually (lazy) load nvm calling it once in the command line.You can't call npx directly:
You'll need to do something like this instead
For this specific case I recommend zsh-nvm