Skip to content

Commit

Permalink
Merge pull request #167 from mattmc3/v1.9.4
Browse files Browse the repository at this point in the history
v1.9.4
  • Loading branch information
mattmc3 committed Dec 3, 2023
2 parents 3f18f35 + 2c32631 commit 414ff3b
Show file tree
Hide file tree
Showing 54 changed files with 574 additions and 225 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.9.3
current_version = 1.9.4
parse = v?(?P<major>\d+)\.(?P<minor>\d+)\.(?P<revision>\d+)
serialize = {major}.{minor}.{revision}

Expand Down
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# antidote

[![MIT License](https://img.shields.io/badge/license-MIT-007EC7.svg)](/LICENSE)
![version](https://img.shields.io/badge/version-v1.9.3-df5e88)
![version](https://img.shields.io/badge/version-v1.9.4-df5e88)

<a title="GetAntidote"
href="https://getantidote.github.io"
Expand All @@ -16,6 +16,22 @@
[Antidote][getantidote] is a feature-complete Zsh implementation of the legacy [Antibody][antibody] plugin manager, which in turn was derived from [Antigen][antigen]. Antidote not only aims to provide continuity for those legacy plugin managers, but also to delight new users with high-performance, easy-to-use Zsh plugin management.

## NOTICE

**The planned upcoming 2.0 release will stop defaulting to compatibility with antibody.** If maintaining compatibility with antibody is important to you, you can ensure that your config remains compatible by add the following `zstyle` to your config **now**, before the 2.0 release goes live:

```zsh
zstyle ':antidote:compatibility-mode' 'antibody'
```

Breaking compatibility by default will allow antidote to continue to grow and gain new features, as well as fix some long-standing issues that have always been present in antibody, for example:

- In 2.0, `fpath` can be fully set at the beginning of your bundles in you static file, making setting up completion bundles properly way easier and less frustrating ([#74](https://github.com/mattmc3/antidote/discussions/74), [#144](https://github.com/mattmc3/antidote/issues/144)).
- bundles will no longer default to using fugly directory names ($ANTIDOTE_HOME/https-COLON--SLASH--SLASH-github.com-SLASH-foo-SLASH-bar), making `zstyle ':antidote:bundle' use-friendly-names on` obsolete.
- probably some other minor deviations as well

Just to be clear, if you don't specifically care about backwards compatibility with antibody, you do not need to change a thing. 2.x will not break your 1.x antidote config. If you do care, be sure to add the compatibility mode `zstyle` above to your config **now**, before the 2.0 release.

## Usage

Basic usage should look really familiar to you if you have used Antibody or Antigen. Bundles (aka: Zsh plugins) are stored in a file typically called `.zsh_plugins.txt`.
Expand Down
4 changes: 2 additions & 2 deletions antidote.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ if test -z "$ZSH_VERSION"; then
echo >&2 "antidote: Expecting zsh. Found '$shellname'."
return 1
else
autoload -Uz is-at-least
builtin autoload -Uz is-at-least
if ! is-at-least 5.4.2; then
echo >&2 "antidote: Unsupported Zsh version '$ZSH_VERSION'. Expecting Zsh >5.4.2."
return 1
fi

typeset -f __antidote_setup &>/dev/null && unfunction __antidote_setup
0=${(%):-%N}
autoload -Uz ${0:A:h}/functions/__antidote_setup
builtin autoload -Uz ${0:A:h}/functions/__antidote_setup
__antidote_setup
fi
27 changes: 27 additions & 0 deletions functions/__antidote_bundle_zcompile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/zsh

### Compile bundles
#function __antidote_bundle_zcompile {
emulate -L zsh; setopt local_options $_adote_funcopts
builtin autoload -Uz zrecompile

local -a bundles
if [[ -z "$1" ]]; then
bundles=($(antidote-list --dirs))
elif [[ -f "$1" ]]; then
zrecompile -pq "$1"
return
elif [[ -d "$1" ]]; then
bundles=($1)
else
bundles=($(antidote-path "$1"))
fi

local bundle zfile
for bundle in $bundles; do
for zfile in ${bundle}/**/*.zsh{,-theme}(N); do
[[ $zfile != */test-data/* ]] || continue
zrecompile -pq "$zfile"
done
done
# }
15 changes: 15 additions & 0 deletions functions/__antidote_collect_input
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/zsh

### Collect <redirected or piped| input
#function __antidote_collect_input {
local -a input=()
if (( $# > 0 )); then
input=("${(s.\n.)${@}}")
elif [[ ! -t 0 ]]; then
local data
while IFS= read -r data || [[ -n "$data" ]]; do
input+=("$data")
done
fi
printf '%s\n' "${input[@]}"
#}
4 changes: 2 additions & 2 deletions functions/__antidote_setup
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
for fn in ${0:A:h}/*; do
[[ ${fn:t} != '__antidote_setup' ]] || continue
if typeset -f ${fn:t} > /dev/null; then
unfunction ${fn:t}
unfunction -- ${fn:t}
fi

# autoload extensionless function files
Expand All @@ -20,7 +20,7 @@
export MANPATH="${0:A:h:h}/man:$MANPATH"
fi

autoload -Uz is-at-least
builtin autoload -Uz is-at-least
if is-at-least 5.8; then
# the -F option was added in 5.8
typeset -gHa _adote_zparopt_flags=( -D -M -F )
Expand Down
2 changes: 1 addition & 1 deletion functions/__antidote_version
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#function __antidote_version {
emulate -L zsh; setopt local_options $_adote_funcopts
0=${(%):-%x}
local ver='1.9.3'
local ver='1.9.4'
local gitsha=$(git -C "${0:A:h:h}" rev-parse --short HEAD 2>/dev/null)
[[ -z "$gitsha" ]] || ver="$ver ($gitsha)"
print "antidote version $ver"
Expand Down
26 changes: 17 additions & 9 deletions functions/antidote-bundle
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,25 @@

# handle bundles as newline delimited arg strings,
# or as <redirected or piped| input
local -a bundles=()
if (( $# > 0 )); then
bundles=("${(s.\n.)${@}}")
elif [[ ! -t 0 ]]; then
local data
while IFS= read -r data || [[ -n "$data" ]]; do
bundles+=($data)
done
fi
local -a bundles=("${(@f)$(__antidote_collect_input "$@")}")
(( $#bundles )) || return 1

# output static file compilation
local -a zcompile_script=(
"function {"
' 0=${(%):-%x}'
' local staticfile=${0:A}'
' [[ -e ${staticfile} ]] || return 1'
' if [[ ! -s ${staticfile}.zwc || ${staticfile} -nt ${staticfile}.zwc ]]; then'
' builtin autoload -Uz zrecompile'
' zrecompile -pq ${staticfile}'
' fi'
'}'
)
if zstyle -t ':antidote:static' zcompile; then
printf '%s\n' $zcompile_script
fi

# antidote-script also clones, but this way we can do it all at once in parallel!
if (( $#bundles > 1 )); then
source <(printf '%s\n' $bundles | __antidote_bulk_clone)
Expand Down
3 changes: 3 additions & 0 deletions functions/antidote-load
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@

if [[ ! $staticfile -nt $bundlefile ]] || [[ $force_bundle -eq 1 ]]; then
antidote bundle <"$bundlefile" >|"$staticfile"
if [[ -r "${staticfile}.zwc" ]] && zstyle -T ':antidote:static' zcompile; then
command rm -f -- "${staticfile}.zwc"
fi
fi
source "$staticfile"
#}
26 changes: 17 additions & 9 deletions functions/antidote-path
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,25 @@
return
fi

if [[ $# -eq 0 ]]; then
local -a bundles=("${(@f)$(__antidote_collect_input "$@")}")
if (( $#bundles == 0 )); then
print -ru2 "antidote: error: required argument 'bundle' not provided, try --help"
return 1
fi

local bundle="$1"
local bundledir=$(__antidote_bundle_dir $bundle)
if [[ ! -d $bundledir ]]; then
print -ru2 "antidote: error: $bundle does not exist in cloned paths"
return 1
else
print "$bundledir"
fi
local bundle bundledir
local -a results=()
for bundle in $bundles; do
if [[ $bundle == '$'* ]] && [[ $bundle != *'('* ]] && [[ $bundle != *';'* ]]; then
bundle=$(eval print $bundle)
fi
bundledir=$(__antidote_bundle_dir $bundle)
if [[ ! -d $bundledir ]]; then
print -ru2 "antidote: error: $bundle does not exist in cloned paths"
return 1
else
results+=("$bundledir")
fi
done
print -l -- $results
#}
78 changes: 53 additions & 25 deletions functions/antidote-script
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
local MATCH MBEGIN MEND; local -a match mbegin mend # appease 'warn_create_global'
local REPLY=

local o_help o_kind o_path o_branch o_cond o_autoload o_pre o_post
local o_help o_kind o_path o_branch o_cond o_autoload o_pre o_post o_fpath_rule
zparseopts $_adote_zparopt_flags -- \
h=o_help -help=h \
a:=o_autoload -autoload:=a \
Expand All @@ -27,11 +27,15 @@
p:=o_path -path:=p \
-pre:=o_pre \
-post:=o_post \
-fpath-rule:=o_fpath_rule \
c:=o_cond -conditional:=c ||
return 1

# set defaults
(( $#o_kind )) || o_kind=(--kind zsh)
if ! (( $#o_fpath_rule )); then
zstyle -a ':antidote:fpath' rule 'o_fpath_rule' || o_fpath_rule=(append)
fi

# strip '=' or ':' from beginning of arg values
local re='^[=:]?(.+)$'
Expand All @@ -42,12 +46,18 @@
[[ $o_branch[-1] =~ $re ]] && o_branch[-1]=$match
[[ $o_pre[-1] =~ $re ]] && o_pre[-1]=$match
[[ $o_post[-1] =~ $re ]] && o_post[-1]=$match
[[ $o_fpath_rule[-1] =~ $re ]] && o_fpath_rule[-1]=$match

local supported_kind_vals=(autoload clone defer fpath path zsh)
if (( $#o_kind )) && ! (( $supported_kind_vals[(Ie)$o_kind[-1]] )); then
print -ru2 "antidote: error: unexpected kind value: '$o_kind[-1]'" && return 1
fi

local supported_fpath_rules=(append prepend)
if ! (( $supported_fpath_rules[(Ie)$o_fpath_rule[-1]] )); then
print -ru2 "antidote: error: unexpected fpath rule: '$o_fpath_rule[-1]'" && return 1
fi

local bundle=$1
if [[ -z "$bundle" ]]; then
print -ru2 "antidote: error: bundle argument expected" && return 1
Expand All @@ -73,15 +83,20 @@
[[ $? -eq 0 ]] || return 1
fi

# if we only needed to clone the bundle, we're done
[[ "$o_kind[-1]" != "clone" ]] || return
# if we only needed to clone the bundle, compile and we're done
if [[ "$o_kind[-1]" == "clone" ]]; then
if zstyle -t ":antidote:bundle:$bundle" zcompile; then
__antidote_bundle_zcompile $bundle_path
fi
return
fi

# add path to bundle
[[ -n "$o_path[-1]" ]] && bundle_path+="/$o_path[-1]"

# handle defer pre-reqs first
local dopts zsh_defer='zsh-defer'
zstyle -s ":antidote:plugin:${bundle}" defer-options 'dopts'
zstyle -s ":antidote:bundle:${bundle}" defer-options 'dopts'
[[ -n "$dopts" ]] && zsh_defer="zsh-defer $dopts"

# generate the script
Expand All @@ -103,41 +118,54 @@

# handle autoloading before sourcing
if (( $#o_autoload )); then
script+=(
"fpath+=( ${bundle_path}/${o_autoload[-1]} )"
"autoload -Uz \$fpath[-1]/*(N.:t)"
)
if [[ "$o_fpath_rule[-1]" == prepend ]]; then
script+=("fpath=( ${bundle_path}/${o_autoload[-1]} \$fpath )")
else
script+=("fpath+=( ${bundle_path}/${o_autoload[-1]} )")
fi
script+=( "builtin autoload -Uz \$fpath[-1]/*(N.:t)" )
fi

# generate load script
bundle_type="$(__antidote_bundle_type $bundle_path)"
local fpath_script
if [[ "$o_fpath_rule[-1]" == prepend ]]; then
fpath_script="fpath=( $bundle_path \$fpath )"
else
fpath_script="fpath+=( $bundle_path )"
fi

if [[ "$o_kind[-1]" == fpath ]]; then
# fpath
script+="fpath+=( $bundle_path )"
script+="$fpath_script"
elif [[ "$o_kind[-1]" == path ]]; then
# path
script+="export PATH=\"$bundle_path:\$PATH\""
elif [[ "$o_kind[-1]" == autoload ]]; then
# autoload
script+=(
"fpath+=( $bundle_path )"
"autoload -Uz \$fpath[-1]/*(N.:t)"
"$fpath_script"
"builtin autoload -Uz \$fpath[-1]/*(N.:t)"
)
elif [[ $bundle_type == file ]]; then
# file
script+="$source_cmd $bundle_path"
else
# directory/default
local initfile initfiles
initfiles=(${(@f)$(__antidote_initfiles $bundle_path)})
# if no init file was found, assume the default
if [[ $#initfiles -eq 0 ]]; then
initfiles=($bundle_path/${bundle_path:t}.plugin.zsh)
if zstyle -t ":antidote:bundle:$bundle" zcompile; then
__antidote_bundle_zcompile $bundle_path
fi
if [[ $bundle_type == file ]]; then
script+="$source_cmd $bundle_path"
else
# directory/default
local initfile initfiles
initfiles=(${(@f)$(__antidote_initfiles $bundle_path)})
# if no init file was found, assume the default
if [[ $#initfiles -eq 0 ]]; then
initfiles=($bundle_path/${bundle_path:t}.plugin.zsh)
fi
script+="$fpath_script"
for initfile in $initfiles; do
script+="$source_cmd $initfile"
done
fi
script+="fpath+=( $bundle_path )"
for initfile in $initfiles; do
script+="$source_cmd $initfile"
done
fi

# add post-load function
Expand All @@ -150,7 +178,7 @@
fi

# mark bundle as loaded
# script+="zstyle ':antidote:plugin:${bundle_name}' loaded yes"
# script+="zstyle ':antidote:bundle:${bundle_name}' loaded yes"

# wrap conditional
if [[ -n "$o_cond[-1]" ]]; then
Expand Down
Loading

0 comments on commit 414ff3b

Please sign in to comment.