Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use function scope to source external bundles #713

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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
18 changes: 9 additions & 9 deletions bin/antigen.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -1816,7 +1816,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 @@ -1891,14 +1891,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 @@ -1934,9 +1934,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 @@ -1948,13 +1948,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 @@ -1964,13 +1964,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