Skip to content

Commit

Permalink
Initial binary support (zsh-users#299)
Browse files Browse the repository at this point in the history
  • Loading branch information
desyncr committed Dec 10, 2016
1 parent e95d7d1 commit 53e2315
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 32 deletions.
65 changes: 37 additions & 28 deletions bin/antigen.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -115,24 +115,10 @@ fi
-antigen-bundle-short-name () {
echo "$@" | sed -E "s|.*/(.*/.*).*?|\1|"|sed -E "s|\.git.*$||g"
}
<<<<<<< 43e25019e32cb09ef4249220920aa61c6299d437
# Echo the bundle specs as in the record. The first line is not echoed since it
# is a blank line.
-antigen-echo-record () {
echo "$_ANTIGEN_BUNDLE_RECORD" | sed -n '1!p'
=======
# Returns bundles flagged as make_local_clone
#
# Usage
# -antigen-cloned-bundles
#
# Returns
# Bundle metadata
-antigen-get-cloned-bundles() {
-antigen-echo-record |
awk '$4 == "true" {print $1}' |
sort -u
>>>>>>> `antigen update` command handle single bundle (#326)
}
# Filters _ANTIGEN_BUNDLE_RECORD for $1
#
Expand Down Expand Up @@ -229,6 +215,18 @@ fi

return 0
}
# Returns bundles flagged as make_local_clone
#
# Usage
# -antigen-cloned-bundles
#
# Returns
# Bundle metadata
-antigen-get-cloned-bundles() {
-antigen-echo-record |
awk '$4 == "true" {print $1}' |
sort -u
}
# Updates _ANTIGEN_INTERACTIVE environment variable to reflect
# if antigen is running in an interactive shell or from sourcing.
#
Expand Down Expand Up @@ -300,6 +298,10 @@ fi
echo "${(j:\n:)bundle_files}"
return
fi

# Add to PATH (binary bundle)
echo "$location"
return
}
# Parses a bundle url in bundle-metadata format: url[|branch]
-antigen-parse-bundle-url() {
Expand Down Expand Up @@ -525,10 +527,12 @@ fi
local src

for src in $(-antigen-load-list "$url" "$loc" "$make_local_clone"); do
# TODO Refactor this out
if [[ -d "$src" ]]; then
if (( ! ${fpath[(I)$location]} )); then
fpath=($location $fpath)
fi
if (( ! ${fpath[(I)$src]} )); then
fpath=($src $fpath)
fi
PATH="$PATH:$src"
else
# Hack away local variables. See https://github.com/zsh-users/antigen/issues/122
# This is needed to seek-and-destroy local variable definitions *outside*
Expand Down Expand Up @@ -685,17 +689,6 @@ antigen-apply () {
fi
unset _zdotdir_set
}
antigen-bundles () {
# Bulk add many bundles at one go. Empty lines and lines starting with a `#`
# are ignored. Everything else is given to `antigen-bundle` as is, no
# quoting rules applied.
local line
grep '^[[:space:]]*[^[:space:]#]' | while read line; do
# Using `eval` so that we can use the shell-style quoting in each line
# piped to `antigen-bundles`.
eval "antigen-bundle $line"
done
}
# Syntaxes
# antigen-bundle <url> [<loc>=/]
# Keyword only arguments:
Expand Down Expand Up @@ -737,6 +730,17 @@ antigen-bundle () {
_ANTIGEN_BUNDLE_RECORD="$_ANTIGEN_BUNDLE_RECORD\n$bundle_record"
fi
}
antigen-bundles () {
# Bulk add many bundles at one go. Empty lines and lines starting with a `#`
# are ignored. Everything else is given to `antigen-bundle` as is, no
# quoting rules applied.
local line
grep '^[[:space:]]*[^[:space:]#]' | while read line; do
# Using `eval` so that we can use the shell-style quoting in each line
# piped to `antigen-bundles`.
eval "antigen-bundle $line"
done
}
antigen-cleanup () {

# Cleanup unused repositories.
Expand Down Expand Up @@ -1248,6 +1252,7 @@ _antigen () {
# Nothing. Generates _ZCACHE_META_PATH and _ZCACHE_PAYLOAD_PATH
-zcache-generate-cache () {
local -aU _extensions_paths
local -aU _binary_paths
local -a _bundles_meta
local _payload=''
local location
Expand All @@ -1269,9 +1274,12 @@ _antigen () {
_payload+="#-- SOURCE: $line\NL"
_payload+=$(-zcache-process-source "$line" "$btype")
_payload+="\NL;#-- END SOURCE\NL"
elif [[ -d "$line" ]]; then
_binary_paths+=($line)
fi
done
# TODO Refactor this out
if $make_local_clone; then
location="$(-antigen-get-clone-dir "$url")/$loc"
else
Expand All @@ -1287,6 +1295,7 @@ _antigen () {
_payload+="$(functions -- _antigen)"
_payload+="\NL"
_payload+="fpath+=(${_extensions_paths[@]})\NL"
_payload+="PATH=\"\$PATH:${_binary_paths[@]}\"\NL"
_payload+="unset __ZCACHE_FILE_PATH\NL"
# \NL (\n) prefix is for backward compatibility
_payload+="export _ANTIGEN_BUNDLE_RECORD=\"\NL${(j:\NL:)_bundles_meta}\"\NL"
Expand Down
5 changes: 5 additions & 0 deletions src/ext/zcache/functions.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
# Nothing. Generates _ZCACHE_META_PATH and _ZCACHE_PAYLOAD_PATH
-zcache-generate-cache () {
local -aU _extensions_paths
local -aU _binary_paths
local -a _bundles_meta
local _payload=''
local location
Expand All @@ -83,9 +84,12 @@
_payload+="#-- SOURCE: $line\NL"
_payload+=$(-zcache-process-source "$line" "$btype")
_payload+="\NL;#-- END SOURCE\NL"
elif [[ -d "$line" ]]; then
_binary_paths+=($line)
fi
done

# TODO Refactor this out
if $make_local_clone; then
location="$(-antigen-get-clone-dir "$url")/$loc"
else
Expand All @@ -101,6 +105,7 @@
_payload+="$(functions -- _antigen)"
_payload+="\NL"
_payload+="fpath+=(${_extensions_paths[@]})\NL"
_payload+="PATH=\"\$PATH:${_binary_paths[@]}\"\NL"
_payload+="unset __ZCACHE_FILE_PATH\NL"
# \NL (\n) prefix is for backward compatibility
_payload+="export _ANTIGEN_BUNDLE_RECORD=\"\NL${(j:\NL:)_bundles_meta}\"\NL"
Expand Down
4 changes: 4 additions & 0 deletions src/helpers/load-list.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@
echo "${(j:\n:)bundle_files}"
return
fi

# Add to PATH (binary bundle)
echo "$location"
return
}
8 changes: 5 additions & 3 deletions src/lib/load.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
local src

for src in $(-antigen-load-list "$url" "$loc" "$make_local_clone"); do
# TODO Refactor this out
if [[ -d "$src" ]]; then
if (( ! ${fpath[(I)$location]} )); then
fpath=($location $fpath)
fi
if (( ! ${fpath[(I)$src]} )); then
fpath=($src $fpath)
fi
PATH="$PATH:$src"
else
# Hack away local variables. See https://github.com/zsh-users/antigen/issues/122
# This is needed to seek-and-destroy local variable definitions *outside*
Expand Down
17 changes: 17 additions & 0 deletions tests/.zshenv
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,20 @@ echo 'alias unsourced-alias="echo unsourced-alias"' > "$PLUGIN_DIR2"/aliases.zsh
pg2 add .
pg2 commit -m 'Initial commit'
} > /dev/null

# Another test plugin.

export PLUGIN_DIR3="$PWD/test-plugin3"
mkdir "$PLUGIN_DIR3"

# A wrapper function over `git` to work with the test plugin repo.
alias pg3='git --git-dir "$PLUGIN_DIR3/.git" --work-tree "$PLUGIN_DIR3"'

echo "echo '######'" > "$PLUGIN_DIR3"/hr
chmod u+x "$PLUGIN_DIR3"/hr

{
pg3 init
pg3 add .
pg3 commit -m 'Initial commit'
} > /dev/null
10 changes: 10 additions & 0 deletions tests/bundle.t
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,13 @@ Handle local bundles (--no-local-clone).

$ -antigen-bundle-short-name "/home/user/local-bundle"
user/local-bundle

Load a binary bundle.

$ antigen-bundle $PLUGIN_DIR3 &> /dev/null
$ hr
######

$ echo $PATH | grep test-plugin3
*plugin3* (glob)

2 changes: 1 addition & 1 deletion tests/cache.t
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Respect escape sequences.
Cache is saved correctly.
$ cat $_ZCACHE_PAYLOAD_PATH | wc -l
54
55
$ cat $_ZCACHE_PAYLOAD_PATH | grep -Pzc 'hehe2"\nalias prompt'
1
Expand Down

0 comments on commit 53e2315

Please sign in to comment.