Skip to content

Commit

Permalink
Merge pull request #2 from belak/fix-plugin-loading
Browse files Browse the repository at this point in the history
Use function scope to source external bundles
see zsh-users#713
  • Loading branch information
crazy-matt authored Jan 12, 2021
2 parents 19b3989 + 896ed4a commit ca63851
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
18 changes: 9 additions & 9 deletions bin/antigen.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -1817,7 +1817,7 @@ typeset -g _ZCACHE_CAPTURE_PREFIX
}' >>! "$compat"
record="$compat"
fi
_sources+=("source '${record}';"$'\n')
_sources+=("() source '${record}';"$'\n')
elif [[ -d $record ]]; then
_PATH+=("${record}")
_fpath+=("${record}")
Expand Down Expand Up @@ -1892,14 +1892,14 @@ EOC

# Cache auto config files to check for changes (.zshrc, .antigenrc etc)
-antigen-set-default ANTIGEN_AUTO_CONFIG true

# Default cache path.
-antigen-set-default ANTIGEN_CACHE $ADOTDIR/init.zsh
-antigen-set-default ANTIGEN_RSRC $ADOTDIR/.resources
if [[ $ANTIGEN_CACHE == false ]]; then
return 1
fi

return 0
}

Expand Down Expand Up @@ -1935,9 +1935,9 @@ EOC
antigen-remove-hook -antigen-load-source-cached
antigen-remove-hook antigen-bundle-cached
}

antigen-add-hook antigen-apply antigen-apply-cached post once

# Defer antigen-bundle.
antigen-bundle-cached () {
# Return an error is not bundle name/url is passed or a heredoc is misused,
Expand All @@ -1949,13 +1949,13 @@ EOC
_ZCACHE_CAPTURE_BUNDLE+=("${(j: :)${@}}")
}
antigen-add-hook antigen-bundle antigen-bundle-cached pre

# Defer loading.
-antigen-load-env-cached () {
local bundle
typeset -A bundle; bundle=($@)
local location=${bundle[dir]}/${bundle[loc]}

# Load to path if there is no sourceable
if [[ ${bundle[loc]} == "/" ]]; then
_ZCACHE_BUNDLE_SOURCE+=("${location}")
Expand All @@ -1965,13 +1965,13 @@ EOC
_ZCACHE_BUNDLE_SOURCE+=("${location}")
}
antigen-add-hook -antigen-load-env -antigen-load-env-cached replace

# Defer sourcing.
-antigen-load-source-cached () {
_ZCACHE_BUNDLE_SOURCE+=($@)
}
antigen-add-hook -antigen-load-source -antigen-load-source-cached replace

return 0
}

Expand Down
18 changes: 9 additions & 9 deletions src/ext/cache.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ typeset -g _ZCACHE_CAPTURE_PREFIX
}' >>! "$compat"
record="$compat"
fi
_sources+=("source '${record}';"$'\n')
_sources+=("() source '${record}';"$'\n')
elif [[ -d $record ]]; then
_PATH+=("${record}")
_fpath+=("${record}")
Expand Down Expand Up @@ -107,14 +107,14 @@ EOC

# Cache auto config files to check for changes (.zshrc, .antigenrc etc)
-antigen-set-default ANTIGEN_AUTO_CONFIG true

# Default cache path.
-antigen-set-default ANTIGEN_CACHE $ADOTDIR/init.zsh
-antigen-set-default ANTIGEN_RSRC $ADOTDIR/.resources
if [[ $ANTIGEN_CACHE == false ]]; then
return 1
fi

return 0
}

Expand Down Expand Up @@ -150,9 +150,9 @@ EOC
antigen-remove-hook -antigen-load-source-cached
antigen-remove-hook antigen-bundle-cached
}

antigen-add-hook antigen-apply antigen-apply-cached post once

# Defer antigen-bundle.
antigen-bundle-cached () {
# Return an error is not bundle name/url is passed or a heredoc is misused,
Expand All @@ -164,13 +164,13 @@ EOC
_ZCACHE_CAPTURE_BUNDLE+=("${(j: :)${@}}")
}
antigen-add-hook antigen-bundle antigen-bundle-cached pre

# Defer loading.
-antigen-load-env-cached () {
local bundle
typeset -A bundle; bundle=($@)
local location=${bundle[dir]}/${bundle[loc]}

# Load to path if there is no sourceable
if [[ ${bundle[loc]} == "/" ]]; then
_ZCACHE_BUNDLE_SOURCE+=("${location}")
Expand All @@ -180,13 +180,13 @@ EOC
_ZCACHE_BUNDLE_SOURCE+=("${location}")
}
antigen-add-hook -antigen-load-env -antigen-load-env-cached replace

# Defer sourcing.
-antigen-load-source-cached () {
_ZCACHE_BUNDLE_SOURCE+=($@)
}
antigen-add-hook -antigen-load-source -antigen-load-source-cached replace

return 0
}

Expand Down

0 comments on commit ca63851

Please sign in to comment.