add lazy-loading of setup scripts for commands that aren't used very often

This commit is contained in:
dmitmel 2018-06-15 16:50:24 +03:00
parent 682ae85d81
commit 93efc97f14
2 changed files with 17 additions and 6 deletions

View file

@ -15,3 +15,17 @@ command_exists() {
source_if_exists() {
[[ -f $1 ]] && source "$1"
}
run_before() {
local command="$1"
local init_command="$2"
eval "$(cat <<EOF
$command() {
unfunction $command
$init_command
$command \$@
}
EOF
)"
}

9
zshrc
View file

@ -19,9 +19,6 @@ for script in "$DOTFILES_DIR"/{functions,path,exports,aliases,oh-my-zsh}.zsh; do
source "$script"
done
# rbenv
command_exists rbenv && eval "$(rbenv init -)"
# sdkman
source_if_exists "$SDKMAN_DIR/bin/sdkman-init.sh"
# Yarn completion
source_if_exists "/usr/local/lib/node_modules/yarn-completions/node_modules/tabtab/.completions/yarn.zsh"
run_before rbenv 'eval "$(rbenv init -)"'
run_before sdk 'source_if_exists "$SDKMAN_DIR/bin/sdkman-init.sh"'
run_before yarn 'source_if_exists "$(yarn global dir)/node_modules/tabtab/.completions/yarn.zsh"'