removed windows and linux split subdir
This commit is contained in:
parent
83dda10fa8
commit
065b982734
280 changed files with 9053 additions and 426 deletions
38
.antidote/functions/__antidote_bulk_clone
Normal file
38
.antidote/functions/__antidote_bulk_clone
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
#!/bin/zsh
|
||||
|
||||
### Generate background clone commands
|
||||
#function __antidote_bulk_clone {
|
||||
emulate -L zsh; setopt local_options $_adote_funcopts
|
||||
|
||||
# Allow the user to define zsh-defer repo in case they want to fork it.
|
||||
local zsh_defer_bundle
|
||||
zstyle -s ':antidote:defer' bundle 'zsh_defer_bundle' \
|
||||
|| zsh_defer_bundle='romkatv/zsh-defer'
|
||||
|
||||
# get a list of clonable repos from a bundle file
|
||||
$__adote_awkcmd -v ZSH_DEFER_BUNDLE=$zsh_defer_bundle '
|
||||
BEGIN { RS="[\r\n]" }
|
||||
|
||||
# initialize vars
|
||||
{ bundle=""; opts="--kind clone" }
|
||||
|
||||
# skip blank or commented lines
|
||||
/^ *(#.+)?$/ { next }
|
||||
|
||||
# clone zsh-defer
|
||||
/kind:defer/ { print "antidote-script --kind clone " ZSH_DEFER_BUNDLE " &" }
|
||||
|
||||
# handle user/repo and URL forms
|
||||
$1~/^[^\/]+\/[^\/]+$/ { bundle=$1 }
|
||||
$1~/^(https?:|(ssh|git)@)/ { bundle=$1 }
|
||||
|
||||
# find branch annotation if it exists
|
||||
match($0, /branch:[^\t ]+/) { opts=opts " --branch " substr($0, RSTART+7, RLENGTH-7) }
|
||||
|
||||
# print result
|
||||
bundle!=""{ print "antidote-script", opts, bundle, "&" }
|
||||
|
||||
END { print "wait" }
|
||||
|
||||
' "$@" | sort | uniq
|
||||
#}
|
||||
46
.antidote/functions/__antidote_bundle_dir
Normal file
46
.antidote/functions/__antidote_bundle_dir
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#!/bin/zsh
|
||||
|
||||
### Get the name of the bundle dir.
|
||||
#function __antidote_bundle_dir {
|
||||
emulate -L zsh; setopt local_options $_adote_funcopts
|
||||
|
||||
# If the bundle is a repo/URL, then by default we use the legacy antibody format:
|
||||
# `$ANTIDOTE_HOME/https-COLON--SLASH--SLASH-github.com-SLASH-zsh-users-SLASH-zsh-autosuggestions`
|
||||
# With `zstyle ':antidote:bundle' use-friendly-names on`, we can simplify to
|
||||
# `$ANTIDOTE_HOME/zsh-users/zsh-autosuggestions`
|
||||
# If the bundle is a file, use its parent directory.
|
||||
# Otherwise, just assume the bundle is a directory.
|
||||
local MATCH MBEGIN MEND; local -a match mbegin mend # appease 'warn_create_global'
|
||||
|
||||
local bundle="$1"
|
||||
local bundle_type="$(__antidote_bundle_type $bundle)"
|
||||
|
||||
# handle repo bundle paths
|
||||
if [[ "$bundle_type" == (repo|url|sshurl) ]] && [[ ! -e "$bundle_path" ]]; then
|
||||
if zstyle -t ':antidote:bundle' use-friendly-names; then
|
||||
# user/repo format
|
||||
# ex: $ANTIDOTE_HOME/zsh-users/zsh-autosuggestions
|
||||
bundle=${bundle%.git}
|
||||
bundle=${bundle:gs/\:/\/}
|
||||
local parts=( ${(ps./.)bundle} )
|
||||
if [[ $#parts -gt 1 ]]; then
|
||||
print $(antidote-home)/${parts[-2]}/${parts[-1]}
|
||||
else
|
||||
print $(antidote-home)/$bundle
|
||||
fi
|
||||
else
|
||||
# sanitize URL for safe use as a dir name
|
||||
# ex: $ANTIDOTE_HOME/https-COLON--SLASH--SLASH-github.com-SLASH-zsh-users-SLASH-zsh-autosuggestions
|
||||
local url=$(__antidote_tourl $bundle)
|
||||
url=${url%.git}
|
||||
url=${url:gs/\@/-AT-}
|
||||
url=${url:gs/\:/-COLON-}
|
||||
url=${url:gs/\//-SLASH-}
|
||||
print $(antidote-home)/$url
|
||||
fi
|
||||
elif [[ -f "$bundle" ]]; then
|
||||
print ${bundle:A:h}
|
||||
else
|
||||
print ${bundle}
|
||||
fi
|
||||
#}
|
||||
17
.antidote/functions/__antidote_bundle_name
Normal file
17
.antidote/functions/__antidote_bundle_name
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#!/bin/zsh
|
||||
|
||||
### Get the short name of the bundle.
|
||||
#function __antidote_bundle_name {
|
||||
emulate -L zsh; setopt local_options $_adote_funcopts
|
||||
local MATCH MBEGIN MEND; local -a match mbegin mend # appease 'warn_create_global'
|
||||
local bundle=$1
|
||||
local bundle_type="$(__antidote_bundle_type $bundle)"
|
||||
if [[ "$bundle_type" == (url|sshurl) ]] ; then
|
||||
bundle=${bundle%.git}
|
||||
bundle=${bundle:gs/\:/\/}
|
||||
local parts=(${(ps./.)bundle})
|
||||
print ${parts[-2]}/${parts[-1]}
|
||||
else
|
||||
print $bundle | sed -e "s|^\~/|$HOME/|" -e "s|^$HOME|\$HOME|"
|
||||
fi
|
||||
#}
|
||||
47
.antidote/functions/__antidote_bundle_type
Normal file
47
.antidote/functions/__antidote_bundle_type
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
#!/bin/zsh
|
||||
|
||||
### Determine bundle type:
|
||||
### - ? - unknown
|
||||
### - empty - empty string
|
||||
### - file - an existing file
|
||||
### - dir - an existing directory
|
||||
### - path - an non-existant path
|
||||
### - relpath - a relative path
|
||||
### - repo - a git repo (user/repo format)
|
||||
### - sshurl - a git repo (SSH format)
|
||||
### - url - a git repo (URL format)
|
||||
### - word - a word
|
||||
#function __antidote_bundle_type {
|
||||
emulate -L zsh; setopt local_options $_adote_funcopts
|
||||
local bundle=$1
|
||||
|
||||
# Try to expand path bundles with '$' and '~' prefixes so that we get a more
|
||||
# granular result than 'path'.
|
||||
if [[ $bundle == '~/'* ]]; then
|
||||
bundle="${HOME}/${bundle#\~/*}"
|
||||
elif [[ $bundle == '$'* ]] && [[ $bundle != *'('* ]] && [[ $bundle != *';'* ]]; then
|
||||
bundle=$(eval print $bundle)
|
||||
fi
|
||||
|
||||
# Determine the bundle type.
|
||||
local result
|
||||
if [[ -e "$bundle" ]]; then
|
||||
[[ -f $bundle ]] && result=file || result=dir
|
||||
elif [[ -z "${bundle// }" ]]; then
|
||||
result=empty
|
||||
else
|
||||
case "$bundle" in
|
||||
(/|~|'$')*) result=path ;;
|
||||
*://*) result=url ;;
|
||||
*@*:*/*) result=sshurl ;;
|
||||
*(:|@)*) result='?' ;;
|
||||
*/*/*) result=relpath ;;
|
||||
*/) result=relpath ;;
|
||||
*/*) result=repo ;;
|
||||
*) result=word ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
typeset -g REPLY=$result
|
||||
print $result
|
||||
#}
|
||||
27
.antidote/functions/__antidote_bundle_zcompile
Normal file
27
.antidote/functions/__antidote_bundle_zcompile
Normal file
|
|
@ -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
.antidote/functions/__antidote_collect_input
Normal file
15
.antidote/functions/__antidote_collect_input
Normal file
|
|
@ -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[@]}"
|
||||
#}
|
||||
32
.antidote/functions/__antidote_del
Normal file
32
.antidote/functions/__antidote_del
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#!/bin/zsh
|
||||
# Call me paranoid, but I want to be really certain antidote will never rm something it
|
||||
# shouldn't. This function wraps rm to double check that any paths being removed are
|
||||
# valid. If it's not in your $HOME or $TMPDIR, we need to block it.
|
||||
|
||||
#function __antidote_del {
|
||||
emulate -L zsh; setopt local_options
|
||||
|
||||
local -a rmflags rmpaths
|
||||
local p
|
||||
|
||||
while (( $# )); do
|
||||
case "$1" in
|
||||
--) shift; break ;;
|
||||
-*) rmflags+=($1) ;;
|
||||
*) break ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
(( $# > 0 )) || return 1
|
||||
|
||||
for p in $@; do
|
||||
p="${p:a}"
|
||||
if [[ "$p" != $HOME/* ]] && [[ "$p" != ${TMPDIR:-/tmp}/* ]]; then
|
||||
print -ru2 -- "antidote: Blocked attempt to rm path: '$p'."
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
|
||||
command rm ${rmflags[@]} -- "$@"
|
||||
#}
|
||||
13
.antidote/functions/__antidote_filter_defers
Normal file
13
.antidote/functions/__antidote_filter_defers
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#!/bin/zsh
|
||||
|
||||
### Filter all but the first defer block.
|
||||
#function __antidote_filter_defers {
|
||||
emulate -L zsh; setopt local_options $_adote_funcopts
|
||||
$__adote_awkcmd '
|
||||
# filter all but the first time we source zsh-defer (a 4 line if statement)
|
||||
BEGIN { skip=0; found=0 }
|
||||
skip>0 { skip-- }
|
||||
/^if.+functions\[zsh\-defer\]/ { if(!found) found=1; else skip=4 }
|
||||
skip==0 { print }
|
||||
' "$@"
|
||||
#}
|
||||
29
.antidote/functions/__antidote_get_cachedir
Normal file
29
.antidote/functions/__antidote_get_cachedir
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#!/bin/zsh
|
||||
|
||||
### Get the default cache directory per OS
|
||||
#function __antidote_get_cachedir {
|
||||
emulate -L zsh; setopt local_options $_adote_funcopts
|
||||
|
||||
local result
|
||||
if [[ "${OSTYPE}" == darwin* ]]; then
|
||||
result=$HOME/Library/Caches
|
||||
elif [[ "${OSTYPE}" == (cygwin|msys)* ]]; then
|
||||
result=${LOCALAPPDATA:-$LocalAppData}
|
||||
if type cygpath > /dev/null; then
|
||||
result=$(cygpath "$result")
|
||||
fi
|
||||
elif [[ -n "$XDG_CACHE_HOME" ]]; then
|
||||
result=$XDG_CACHE_HOME
|
||||
else
|
||||
result=$HOME/.cache
|
||||
fi
|
||||
|
||||
if [[ -n "$1" ]]; then
|
||||
if [[ $result == *\\* ]] && [[ $result != */* ]]; then
|
||||
result+="\\$1"
|
||||
else
|
||||
result+="/$1"
|
||||
fi
|
||||
fi
|
||||
print -r -- $result
|
||||
#}
|
||||
8
.antidote/functions/__antidote_indent
Normal file
8
.antidote/functions/__antidote_indent
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#!/bin/zsh
|
||||
|
||||
### Indent strings
|
||||
#function __antidote_indent {
|
||||
emulate -L zsh; setopt local_options $_adote_funcopts
|
||||
local -a lines=("${(@f)$(__antidote_collect_input "$@")}")
|
||||
printf ' %s\n' $lines
|
||||
#}
|
||||
17
.antidote/functions/__antidote_initfiles
Normal file
17
.antidote/functions/__antidote_initfiles
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#!/bin/zsh
|
||||
|
||||
### Get the path to a plugin's init file.
|
||||
#function __antidote_initfiles {
|
||||
emulate -L zsh; setopt local_options $_adote_funcopts
|
||||
typeset -ga reply=()
|
||||
local dir=${1:A}
|
||||
local initfiles=($dir/${dir:A:t}.plugin.zsh(N))
|
||||
[[ $#initfiles -gt 0 ]] || initfiles=($dir/*.plugin.zsh(N))
|
||||
[[ $#initfiles -gt 0 ]] || initfiles=($dir/*.zsh(N))
|
||||
[[ $#initfiles -gt 0 ]] || initfiles=($dir/*.sh(N))
|
||||
[[ $#initfiles -gt 0 ]] || initfiles=($dir/*.zsh-theme(N))
|
||||
|
||||
typeset -ga reply=($initfiles)
|
||||
printf "%s\n" ${(u)initfiles[@]}
|
||||
(( $#initfiles )) || return 1
|
||||
#}
|
||||
60
.antidote/functions/__antidote_load_prep
Normal file
60
.antidote/functions/__antidote_load_prep
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
#!/bin/zsh
|
||||
|
||||
### Prep to load
|
||||
#function __antidote_load_prep {
|
||||
emulate -L zsh; setopt local_options $_adote_funcopts
|
||||
|
||||
# pass in bundle file, read from zstyle, or use default .zsh_plugins.txt
|
||||
local bundlefile="$1"
|
||||
if [[ -z "$bundlefile" ]]; then
|
||||
zstyle -s ':antidote:bundle' file 'bundlefile' ||
|
||||
bundlefile=${ZDOTDIR:-$HOME}/.zsh_plugins.txt
|
||||
fi
|
||||
|
||||
# pass in static file, read from zstyle, change extension, or use default .zsh_plugins.zsh
|
||||
local staticfile="$2"
|
||||
if [[ -z "$staticfile" ]]; then
|
||||
zstyle -s ':antidote:static' file 'staticfile'
|
||||
if [[ -z "$staticfile" ]]; then
|
||||
if [[ -z "$bundlefile:t:r" ]]; then
|
||||
staticfile=${bundlefile}.zsh
|
||||
else
|
||||
staticfile=${bundlefile:r}.zsh
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ ! -e "$bundlefile" ]]; then
|
||||
# the files can't have the same name
|
||||
print -ru2 -- "antidote: bundle file not found '$bundlefile'."
|
||||
return 1
|
||||
elif [[ "$bundlefile" == "$staticfile" ]]; then
|
||||
# the files can't have the same name
|
||||
print -ru2 -- "antidote: bundle file and static file are the same '$bundlefile'."
|
||||
return 1
|
||||
fi
|
||||
|
||||
# regenerate the static file based on whether the bundle file is newer and whether
|
||||
# antidote home exists and is ready to be loaded
|
||||
local force_bundle=0
|
||||
if ! zstyle -t ':antidote:load:checkfile' disabled; then
|
||||
local loadable_check_path="$(antidote-home)/.antidote.load"
|
||||
if [[ ! -e $loadable_check_path ]]; then
|
||||
force_bundle=1
|
||||
[[ -d $loadable_check_path:h ]] || mkdir -p $loadable_check_path:h
|
||||
touch $loadable_check_path
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ ! $staticfile -nt $bundlefile ]] || [[ $force_bundle -eq 1 ]]; then
|
||||
mkdir -p "${staticfile:A:h}"
|
||||
antidote bundle <"$bundlefile" >|"$staticfile"
|
||||
if [[ -r "${staticfile}.zwc" ]] && ! zstyle -t ':antidote:static' zcompile; then
|
||||
__antidote_del -f -- "${staticfile}.zwc"
|
||||
fi
|
||||
fi
|
||||
|
||||
# tell antidote-load what to source
|
||||
typeset -g REPLY=$staticfile
|
||||
#print $REPLY
|
||||
#}
|
||||
41
.antidote/functions/__antidote_parse_bundles
Normal file
41
.antidote/functions/__antidote_parse_bundles
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
#!/bin/zsh
|
||||
|
||||
### Parse antidote's bundle DSL.
|
||||
#function __antidote_parse_bundles {
|
||||
emulate -L zsh; setopt local_options $_adote_funcopts
|
||||
$__adote_awkcmd '
|
||||
BEGIN { RS="[\r\n]" }
|
||||
|
||||
# skip comments and empty lines
|
||||
/^ *$/ || /^ *#/ {next}
|
||||
|
||||
# strip trailing comments
|
||||
{ sub(/[ \t]#.*$/,"",$0) }
|
||||
|
||||
# escape leading $ variables
|
||||
{ sub(/^\$/,"\\$",$0) }
|
||||
|
||||
# handle extension functionality (eg :use ohmyzsh)
|
||||
$1~/^:/ {
|
||||
sub(/^:/,"",$1)
|
||||
printf "antidote-script-" $1
|
||||
for (i=2; i<=NF; i++) {
|
||||
printf " %s",$i
|
||||
}
|
||||
printf "\n"
|
||||
next
|
||||
}
|
||||
|
||||
# move flags to front and call antidote-script
|
||||
{
|
||||
sub(/ #.*$/,"",$0)
|
||||
printf "antidote-script"
|
||||
for (i=2; i<=NF; i++) {
|
||||
sub(/^/,"--",$i)
|
||||
sub(/:/," ",$i)
|
||||
printf " %s",$i
|
||||
}
|
||||
printf " %s\n",$1
|
||||
}
|
||||
' "$@"
|
||||
#}
|
||||
8
.antidote/functions/__antidote_print_path
Normal file
8
.antidote/functions/__antidote_print_path
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#!/bin/zsh
|
||||
### Pretty print a path
|
||||
|
||||
if zstyle -t ':antidote:compatibility-mode' 'antibody'; then
|
||||
echo "$1"
|
||||
else
|
||||
echo "$1" | sed -e "s|^$HOME/|\$HOME/|"
|
||||
fi
|
||||
39
.antidote/functions/__antidote_setup
Normal file
39
.antidote/functions/__antidote_setup
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
#!/bin/zsh
|
||||
|
||||
### Setup antidote.
|
||||
#function __antidote_setup {
|
||||
0=${(%):-%x}
|
||||
fpath=( "${0:A:h}" $fpath )
|
||||
local fn
|
||||
for fn in ${0:A:h}/*; do
|
||||
[[ ${fn:t} != '__antidote_setup' ]] || continue
|
||||
if typeset -f ${fn:t} > /dev/null; then
|
||||
unfunction -- ${fn:t}
|
||||
fi
|
||||
|
||||
# autoload extensionless function files
|
||||
[[ -z "${fn:e}" ]] && autoload -Uz "${fn}"
|
||||
done
|
||||
|
||||
# man pages
|
||||
if [[ "$MANPATH" != *"${0:A:h:h}/man"* ]]; then
|
||||
export MANPATH="${0:A:h:h}/man:$MANPATH"
|
||||
fi
|
||||
|
||||
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 )
|
||||
else
|
||||
typeset -gHa _adote_zparopt_flags=( -D -M )
|
||||
fi
|
||||
|
||||
typeset -gHa _adote_funcopts=( extended_glob no_monitor pipefail )
|
||||
if zstyle -t ':antidote:tests' set-warn-options; then
|
||||
typeset -gHa _adote_funcopts=( $_adote_funcopts warn_create_global warn_nested_var )
|
||||
fi
|
||||
|
||||
gawk --version &>/dev/null && typeset -gH __adote_awkcmd=gawk || typeset -gH __adote_awkcmd=awk
|
||||
typeset -gHi __adote_ksh_arrays
|
||||
typeset -gHi __adote_sh_glob
|
||||
#}
|
||||
13
.antidote/functions/__antidote_tourl
Normal file
13
.antidote/functions/__antidote_tourl
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#!/bin/zsh
|
||||
|
||||
### Get the url from a repo bundle.
|
||||
#function __antidote_tourl {
|
||||
emulate -L zsh; setopt local_options $_adote_funcopts
|
||||
|
||||
local bundle=$1
|
||||
local url=$bundle
|
||||
if [[ $bundle != *://* && $bundle != git@*:*/* ]]; then
|
||||
url=https://github.com/$bundle
|
||||
fi
|
||||
print $url
|
||||
#}
|
||||
27
.antidote/functions/__antidote_usage
Normal file
27
.antidote/functions/__antidote_usage
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#!/bin/zsh
|
||||
|
||||
### Print usage.
|
||||
#function __antidote_usage {
|
||||
emulate -L zsh; setopt local_options $_adote_funcopts
|
||||
cat<<EOS
|
||||
antidote - the cure to slow zsh plugin management
|
||||
|
||||
usage: antidote [<flags>] <command> [<args> ...]
|
||||
|
||||
flags:
|
||||
-h, --help Show context-sensitive help
|
||||
-v, --version Show application version
|
||||
|
||||
commands:
|
||||
help Show documentation
|
||||
load Statically source all bundles from the plugins file
|
||||
bundle Clone bundle(s) and generate the static load script
|
||||
install Clone a new bundle and add it to your plugins file
|
||||
update Update antidote and its cloned bundles
|
||||
purge Remove a cloned bundle
|
||||
home Print where antidote is cloning bundles
|
||||
list List cloned bundles
|
||||
path Print the path of a cloned bundle
|
||||
init Initialize the shell for dynamic bundles
|
||||
EOS
|
||||
#}
|
||||
11
.antidote/functions/__antidote_version
Normal file
11
.antidote/functions/__antidote_version
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#!/bin/zsh
|
||||
|
||||
### Get the antidote version.
|
||||
#function __antidote_version {
|
||||
emulate -L zsh; setopt local_options $_adote_funcopts
|
||||
0=${(%):-%x}
|
||||
local ver='1.9.7'
|
||||
local gitsha=$(git -C "${0:A:h:h}" rev-parse --short HEAD 2>/dev/null)
|
||||
[[ -z "$gitsha" ]] || ver="$ver ($gitsha)"
|
||||
print "antidote version $ver"
|
||||
#}
|
||||
123
.antidote/functions/_antidote
Normal file
123
.antidote/functions/_antidote
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
#compdef antidote
|
||||
|
||||
function _antidote_subcommands {
|
||||
local usage=$(
|
||||
antidote --help |
|
||||
${__adote_awkcmd:-awk} '
|
||||
BEGIN{OFS=":"; p=0}
|
||||
/^commands:$/ {p=1; next}
|
||||
!p{next}
|
||||
{ for(i=3; i<=NF; i++) { $2=$2" "$i } }
|
||||
{ print $1,$2 }
|
||||
'
|
||||
)
|
||||
local -a subcommands=("${(@f)usage}")
|
||||
_describe -t subcommands 'subcommand' subcommands "$@"
|
||||
}
|
||||
|
||||
function _antidote_installed_bundles {
|
||||
local -a bundles=("${(@f)$(antidote list -s)}")
|
||||
_describe 'installed bundles' bundles
|
||||
}
|
||||
|
||||
function _antidote_bundle_kinds {
|
||||
local -a kinds=(
|
||||
'autoload' 'clone' 'defer' 'fpath' 'path' 'zsh'
|
||||
)
|
||||
_describe 'bundle kinds' kinds
|
||||
}
|
||||
|
||||
function _antidote {
|
||||
typeset -A opt_args
|
||||
local context state line
|
||||
local curcontext="$curcontext"
|
||||
local ret=1
|
||||
|
||||
_arguments -C \
|
||||
'(- *)'{-v,--version}'[Show version]' \
|
||||
'(- *)'{-h,--help}'[Show usage information]' \
|
||||
'1: :_antidote_subcommands' \
|
||||
'*:: :->subcmds' && return 0
|
||||
|
||||
case "$state" in
|
||||
(subcmds)
|
||||
case $words[1] in
|
||||
(bundle)
|
||||
_arguments \
|
||||
'(- *)'{-h,--help}'[Show usage information]' \
|
||||
&& ret=0
|
||||
;;
|
||||
(help)
|
||||
_arguments \
|
||||
'(- *)'{-h,--help}'[Show usage information]' \
|
||||
&& ret=0
|
||||
;;
|
||||
(home)
|
||||
_arguments \
|
||||
'(- *)'{-h,--help}'[Show usage information]' \
|
||||
&& ret=0
|
||||
;;
|
||||
(init)
|
||||
_arguments \
|
||||
'(- *)'{-h,--help}'[Show usage information]' \
|
||||
&& ret=0
|
||||
;;
|
||||
(install|script)
|
||||
_arguments \
|
||||
'(- *)'{-h,--help}'[Show usage information]' \
|
||||
'(-k --kind)'{-k,--kind}'[The kind of bundle]:kinds:_antidote_bundle_kinds' \
|
||||
'(-p --path)'{-p,--path}'[A relative subpath within the bundle where the plugin is located]' \
|
||||
'(-a --autoload)'{-a,--autoload}'[A relative subpath within the bundle where autoload function files are located]' \
|
||||
'(-c --conditional)'{-c,--conditional}'[A conditional function used to check whether to load the bundle]' \
|
||||
'(-b --branch)'{-b,--branch}'[The git branch to use]' \
|
||||
'(--pre)--pre[A function to be called prior to loading the bundle]' \
|
||||
'(--post)--post[A function to be called after loading the bundle]' \
|
||||
&& ret=0
|
||||
;;
|
||||
(list)
|
||||
_arguments \
|
||||
'(- *)'{-h,--help}'[Show usage information]' \
|
||||
'(-s --short)'{-s,--short}'[Show shortened repos where possible]' \
|
||||
'(-d --dirs)'{-d,--dirs}'[Show only bundle directories]' \
|
||||
'(-u --url)'{-u,--url}'[Show bundle URLs]' \
|
||||
&& ret=0
|
||||
;;
|
||||
(load)
|
||||
_arguments \
|
||||
'(- *)'{-h,--help}'[Show usage information]' \
|
||||
&& ret=0
|
||||
;;
|
||||
(path)
|
||||
_arguments \
|
||||
'(- *)'{-h,--help}'[Show usage information]' \
|
||||
&& ret=0
|
||||
;;
|
||||
(purge)
|
||||
_arguments \
|
||||
'(- *)'{-h,--help}'[Show usage information]' \
|
||||
'(-a --all)'{-a,--all}'[Purge all cloned bundles]' \
|
||||
"*::antidote bundles:_antidote_installed_bundles" \
|
||||
&& ret=0
|
||||
;;
|
||||
(update)
|
||||
_arguments \
|
||||
'(- *)'{-h,--help}'[Show usage information]' \
|
||||
'(-s --selp)'{-s,--self}'[Update antidote]' \
|
||||
'(-b --bundles)'{-b,--bundles}'[Update bundles]' \
|
||||
&& ret=0
|
||||
;;
|
||||
(*)
|
||||
_arguments \
|
||||
'(- *)'{-h,--help}'[Show usage information]' \
|
||||
'*: :_files' \
|
||||
&& ret=0
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
|
||||
return ret
|
||||
}
|
||||
_antidote "$@"
|
||||
|
||||
# vim: ft=zsh sw=2 ts=2 et
|
||||
16
.antidote/functions/antidote
Normal file
16
.antidote/functions/antidote
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#!/bin/zsh
|
||||
|
||||
### antidote - the cure to slow zsh plugin management
|
||||
#
|
||||
# https://antidote.sh
|
||||
# run `antidote -h` for usage
|
||||
#
|
||||
# Note: this gets overridden if using `antidote init`.
|
||||
#
|
||||
#function antidote {
|
||||
0=${(%):-%x}
|
||||
if ! typeset -f antidote-main > /dev/null; then
|
||||
source ${0:A:h:h}/antidote.zsh
|
||||
fi
|
||||
antidote-main "$@"
|
||||
#}
|
||||
49
.antidote/functions/antidote-bundle
Normal file
49
.antidote/functions/antidote-bundle
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
#!/bin/zsh
|
||||
|
||||
### Clone bundle(s) and generate the static load script.
|
||||
#
|
||||
# usage: antidote bundle [-h|--help] <bundle>...
|
||||
#
|
||||
|
||||
### Clone bundle(s) and generate the static load script.
|
||||
#function antidote-bundle {
|
||||
# Download a bundle and prints its Zsh source line.
|
||||
emulate -L zsh; setopt local_options $_adote_funcopts
|
||||
|
||||
local o_help
|
||||
zparseopts $_adote_zparopt_flags -- h=o_help -help=h || return 1
|
||||
|
||||
if (( $#o_help )); then
|
||||
antidote-help bundle
|
||||
return
|
||||
fi
|
||||
|
||||
# handle bundles as newline delimited arg strings,
|
||||
# or as <redirected or piped| input
|
||||
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)
|
||||
fi
|
||||
|
||||
# generate bundle script
|
||||
source <(printf '%s\n' $bundles | __antidote_parse_bundles) | __antidote_filter_defers
|
||||
#}
|
||||
32
.antidote/functions/antidote-help
Normal file
32
.antidote/functions/antidote-help
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#!/bin/zsh
|
||||
|
||||
### Show antidote documentation.
|
||||
#
|
||||
# usage: antidote [-h|--help] [<command>]
|
||||
# antidote help [<command>]
|
||||
#
|
||||
|
||||
#function antidote-help {
|
||||
emulate -L zsh; setopt local_options $_adote_funcopts
|
||||
|
||||
local o_help
|
||||
zparseopts $_adote_zparopt_flags -- h=o_help -help=h || return 1
|
||||
|
||||
local manpage
|
||||
|
||||
if (( $#o_help )); then
|
||||
manpage=antidote-help
|
||||
elif [[ "$1" == antidote ]]; then
|
||||
manpage=antidote
|
||||
elif [[ -n "$1" ]]; then
|
||||
manpage="antidote-${1}"
|
||||
fi
|
||||
|
||||
if (( $+commands[man] )) && [[ -n "$manpage" ]]; then
|
||||
man "$manpage" || {
|
||||
__antidote_usage && return 1
|
||||
}
|
||||
else
|
||||
__antidote_usage
|
||||
fi
|
||||
#}
|
||||
29
.antidote/functions/antidote-home
Normal file
29
.antidote/functions/antidote-home
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#!/bin/zsh
|
||||
|
||||
### Print where antidote is cloning bundles.
|
||||
#
|
||||
# usage: antidote home [-h|--help]
|
||||
#
|
||||
# Can be overridden by setting `$ANTIDOTE_HOME`.
|
||||
#
|
||||
#function antidote-home {
|
||||
emulate -L zsh; setopt local_options $_adote_funcopts
|
||||
|
||||
typeset -g REPLY=
|
||||
local o_help
|
||||
zparseopts $_adote_zparopt_flags -- h=o_help -help=h || return 1
|
||||
|
||||
if (( $#o_help )); then
|
||||
antidote-help home
|
||||
return
|
||||
fi
|
||||
|
||||
local result
|
||||
if [[ -n "$ANTIDOTE_HOME" ]]; then
|
||||
result=$ANTIDOTE_HOME
|
||||
else
|
||||
result=$(__antidote_get_cachedir "antidote")
|
||||
fi
|
||||
print $result
|
||||
typeset -g REPLY=$result
|
||||
#}
|
||||
33
.antidote/functions/antidote-init
Normal file
33
.antidote/functions/antidote-init
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
#!/bin/zsh
|
||||
|
||||
### Initialize the shell for dynamic bundles.
|
||||
#
|
||||
# usage: antidote init [-h|--help]
|
||||
# source <(antidote init)
|
||||
#
|
||||
# This function changes how the `antidote` command works by sourcing the results of
|
||||
# `antidote bundle` instead of just generating the Zsh script.
|
||||
#function antidote-init {
|
||||
local o_help
|
||||
zparseopts $_adote_zparopt_flags -- h=o_help -help=h || return 1
|
||||
|
||||
if (( $#o_help )); then
|
||||
antidote-help init
|
||||
return
|
||||
fi
|
||||
|
||||
local script=(
|
||||
'#!/usr/bin/env zsh'
|
||||
'function antidote {'
|
||||
' case "$1" in'
|
||||
' bundle)'
|
||||
' source <( antidote-main $@ ) || antidote-main $@'
|
||||
' ;;'
|
||||
' *)'
|
||||
' antidote-main $@'
|
||||
' ;;'
|
||||
' esac'
|
||||
'}'
|
||||
)
|
||||
printf "%s\n" "${script[@]}"
|
||||
#}
|
||||
65
.antidote/functions/antidote-install
Normal file
65
.antidote/functions/antidote-install
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
#!/bin/zsh
|
||||
|
||||
### Clone a new bundle and add it to your plugins file.
|
||||
|
||||
# usage: antidote install [-h|--help] [-k|--kind <kind>] [-p|--path <path>]
|
||||
# [-c|--conditional <func>] [-b|--branch <branch>]
|
||||
# [--pre <func>] [--post <func>]
|
||||
# [-a|--autoload <path>] <bundle> [<bundlefile>]
|
||||
#function antidote-install {
|
||||
emulate -L zsh; setopt local_options $_adote_funcopts
|
||||
|
||||
local -A flag_to_annotation=(
|
||||
'-a' autoload
|
||||
'-b' branch
|
||||
'-c' conditional
|
||||
'-h' help
|
||||
'-k' kind
|
||||
'-p' path
|
||||
)
|
||||
local -a annotations=()
|
||||
local arg
|
||||
while (( $# )); do
|
||||
arg="$1"
|
||||
case "$arg" in
|
||||
-h|--help)
|
||||
antidote-help install
|
||||
return
|
||||
;;
|
||||
--) shift; break ;;
|
||||
--*) annotations+=( "${arg#*--}:$2" ); shift ;;
|
||||
-*) annotations+=( $flag_to_annotation[$arg]:$2 ); shift ;;
|
||||
*) break ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
if [[ $# -eq 0 ]]; then
|
||||
print -ru2 "antidote: error: required argument 'bundle' not provided, try --help"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local bundle=$1
|
||||
local bundlefile=$2
|
||||
if [[ -z "$bundlefile" ]]; then
|
||||
zstyle -s ':antidote:bundle' file 'bundlefile' ||
|
||||
bundlefile=${ZDOTDIR:-$HOME}/.zsh_plugins.txt
|
||||
fi
|
||||
|
||||
local bundledir=$(__antidote_bundle_dir $bundle)
|
||||
if [[ -d "$bundledir" ]]; then
|
||||
print -ru2 "antidote: error: $bundle already installed: $bundledir"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# use antidote bundle to clone our bundle
|
||||
local bundlestr=$bundle
|
||||
(( $#annotations )) && bundlestr+=" $annotations"
|
||||
antidote-bundle "$bundlestr" >/dev/null
|
||||
if [[ $? -ne 0 ]]; then
|
||||
print -ru2 "antidote: unable to install bundle '$bundle'."
|
||||
else
|
||||
print "Adding bundle to '$bundlefile':"
|
||||
print $bundlestr | tee -a $bundlefile
|
||||
fi
|
||||
#}
|
||||
48
.antidote/functions/antidote-list
Normal file
48
.antidote/functions/antidote-list
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
#!/bin/zsh
|
||||
|
||||
### List cloned bundles.
|
||||
#
|
||||
# usage: antidote list [-h|--help] [-s|--short] [-d|--dirs] [-u|--url]
|
||||
#
|
||||
#function antidote-list {
|
||||
emulate -L zsh; setopt local_options $_adote_funcopts
|
||||
|
||||
local o_help o_short o_url o_dirs
|
||||
zparseopts $_adote_zparopt_flags -- \
|
||||
h=o_help -help=h \
|
||||
s=o_short -short=s \
|
||||
u=o_url -url=u \
|
||||
d=o_dirs -dirs=d ||
|
||||
return 1
|
||||
|
||||
if (( $#o_help )); then
|
||||
antidote-help list
|
||||
return
|
||||
fi
|
||||
|
||||
if [[ $# -ne 0 ]]; then
|
||||
print -ru2 "antidote: error: unexpected $1, try --help"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local bundledir
|
||||
local output=()
|
||||
local bundles=($(antidote-home)/**/.git(/N))
|
||||
|
||||
for bundledir in $bundles; do
|
||||
bundledir=${bundledir:h}
|
||||
local url=$(git -C "$bundledir" config remote.origin.url)
|
||||
if (( $#o_dirs )); then
|
||||
output+=($bundledir)
|
||||
elif (( $#o_url )); then
|
||||
output+=($url)
|
||||
elif (( $#o_short )); then
|
||||
url=${url%.git}
|
||||
url=${url#https://github.com/}
|
||||
output+=($url)
|
||||
else
|
||||
output+=("$(printf '%-64s %s\n' $url $bundledir)")
|
||||
fi
|
||||
done
|
||||
(( $#output )) && printf '%s\n' ${(o)output}
|
||||
#}
|
||||
26
.antidote/functions/antidote-load
Normal file
26
.antidote/functions/antidote-load
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
#!/bin/zsh
|
||||
|
||||
### Statically source all bundles from the plugins file.
|
||||
#
|
||||
# usage: antidote load [-h|--help] [<bundlefile> [<staticfile>]]
|
||||
#
|
||||
#function antidote-load {
|
||||
if [[ "$1" == (-h|--help) ]]; then
|
||||
antidote-help load
|
||||
return
|
||||
fi
|
||||
|
||||
# We can't use LOCAL_OPTIONS because sourcing plugins means we'd lose any Zsh options
|
||||
# set in those plugins, so we delegate all the work to __antidote_load_prep where
|
||||
# we can safely use LOCAL_OPTIONS. For this function, we should do the bare minimum
|
||||
# so the user can set whatever crazy Zsh options they want, and antidote doesn't need
|
||||
# to concern itself with that.
|
||||
#
|
||||
# "Is your house on fire, Clark? No, Aunt Bethany, those are the user's Zsh options."
|
||||
#
|
||||
typeset -g REPLY=
|
||||
__antidote_load_prep "$@" || return 1
|
||||
[[ -f "$REPLY" ]] || return 2
|
||||
source "$REPLY"
|
||||
unset REPLY
|
||||
#}
|
||||
49
.antidote/functions/antidote-main
Normal file
49
.antidote/functions/antidote-main
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
#!/bin/zsh
|
||||
|
||||
### The main controller for antidote.
|
||||
# The reason we use `antidote-main` instead putting all of this in `antidote`
|
||||
# is that this allows the `antidote` function to be overridden via `antidote init`.
|
||||
# The init command switches antidote from static mode to dynamic mode, but this
|
||||
# core functionality remains.
|
||||
#function antidote-main {
|
||||
0=${(%):-%x}
|
||||
|
||||
[[ -o KSH_ARRAYS ]] && __adote_ksh_arrays=1 && unsetopt KSH_ARRAYS
|
||||
[[ -o SH_GLOB ]] && __adote_sh_glob=1 && unsetopt SH_GLOB
|
||||
|
||||
local o_help o_version
|
||||
zparseopts ${_adote_zparopt_flags} -- \
|
||||
h=o_help -help=h \
|
||||
v=o_version -version=v ||
|
||||
return 1
|
||||
|
||||
local ret=0
|
||||
|
||||
if (( ${#o_version} )); then
|
||||
__antidote_version
|
||||
|
||||
elif (( ${#o_help} )); then
|
||||
antidote-help "$@"
|
||||
|
||||
elif [[ ${#} -eq 0 ]]; then
|
||||
antidote-help
|
||||
ret=2
|
||||
|
||||
elif [[ "${1}" = help ]]; then
|
||||
local manpage=${2:-antidote}
|
||||
antidote-help $manpage
|
||||
|
||||
elif (( $+functions[antidote-${1}] )); then
|
||||
local cmd=${1}; shift
|
||||
antidote-${cmd} "$@"
|
||||
ret=$?
|
||||
|
||||
else
|
||||
print -ru2 "antidote: command not found '${1}'"
|
||||
ret=1
|
||||
fi
|
||||
|
||||
(( __adote_ksh_arrays )) && __adote_ksh_arrays=0 && setopt KSH_ARRAYS
|
||||
(( __adote_sh_glob )) && __adote_sh_glob=0 && setopt SH_GLOB
|
||||
return $ret
|
||||
#}
|
||||
39
.antidote/functions/antidote-path
Normal file
39
.antidote/functions/antidote-path
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
#!/bin/zsh
|
||||
|
||||
### Print the path of a cloned bundle.
|
||||
#
|
||||
# usage: antidote path [-h|--help] <bundle>
|
||||
#
|
||||
#function antidote-path {
|
||||
emulate -L zsh; setopt local_options $_adote_funcopts
|
||||
|
||||
local o_help
|
||||
zparseopts $_adote_zparopt_flags -- h=o_help -help=h || return 1
|
||||
|
||||
if (( $#o_help )); then
|
||||
antidote-help path
|
||||
return
|
||||
fi
|
||||
|
||||
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 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
|
||||
#}
|
||||
83
.antidote/functions/antidote-purge
Normal file
83
.antidote/functions/antidote-purge
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
#!/bin/zsh
|
||||
|
||||
### Remove a cloned bundle.
|
||||
#
|
||||
# usage: antidote purge [-h|--help] <bundle>
|
||||
# antidote purge [-a|--all]
|
||||
#
|
||||
#function antidote-purge {
|
||||
emulate -L zsh; setopt local_options $_adote_funcopts
|
||||
|
||||
local o_help o_all
|
||||
zparseopts $_adote_zparopt_flags -- \
|
||||
h=o_help -help=h \
|
||||
a=o_all -all=a ||
|
||||
return 1
|
||||
|
||||
if (( $#o_help )); then
|
||||
antidote-help purge
|
||||
return
|
||||
fi
|
||||
|
||||
if [[ $# -eq 0 ]] && ! (( $#o_all )); then
|
||||
print -ru2 "antidote: error: required argument 'bundle' not provided, try --help"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local bundlefile
|
||||
zstyle -s ':antidote:bundle' file 'bundlefile' ||
|
||||
bundlefile=${ZDOTDIR:-$HOME}/.zsh_plugins.txt
|
||||
|
||||
if (( $#o_all )); then
|
||||
# last chance to save the user from themselves
|
||||
local antidote_home="$(antidote-home)"
|
||||
local REPLY
|
||||
zstyle -s ':antidote:purge:all' answer 'REPLY' || {
|
||||
read -q "REPLY?You are about to permanently remove '$antidote_home' and all its contents!"$'\n'"Are you sure [Y/n]? "
|
||||
print
|
||||
}
|
||||
[[ ${REPLY:u} == "Y" ]] || return 1
|
||||
# remove antidote home and static cache file
|
||||
__antidote_del -rf -- "$antidote_home"
|
||||
|
||||
if [[ -e "${bundlefile:r}.zsh" ]]; then
|
||||
zstyle -s ':antidote:purge:all' answer 'REPLY' || {
|
||||
read -q "REPLY?You are about to remove '${bundlefile:t:r}.zsh'"$'\n'"Are you sure [Y/n]? "
|
||||
print
|
||||
}
|
||||
if [[ ${REPLY:u} == "Y" ]]; then
|
||||
local dtstmp=$(date -u '+%Y%m%d_%H%M%S')
|
||||
command mv -f "${bundlefile:r}.zsh" "${bundlefile:r}.${dtstmp}.bak"
|
||||
print "'"${bundlefile:r}.zsh"' backed up to '${bundlefile:t:r}.${dtstmp}.bak'"
|
||||
fi
|
||||
fi
|
||||
print "Antidote purge complete. Be sure to start a new Zsh session."
|
||||
|
||||
else
|
||||
local bundle=$1
|
||||
# make sure the user isn't trying to do something out-of-bounds
|
||||
if [[ -e "$bundle" ]]; then
|
||||
print -ru2 "antidote: error: '$bundle' is not a repo and cannot be removed by antidote."
|
||||
return 2
|
||||
fi
|
||||
|
||||
local bundledir=$(__antidote_bundle_dir $bundle)
|
||||
if [[ ! -d "$bundledir" ]]; then
|
||||
print -ru2 "antidote: error: $bundle does not exist at the expected location: $bundledir"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# remove
|
||||
__antidote_del -rf "$bundledir"
|
||||
print "Removed '$bundle'."
|
||||
|
||||
# attempt to comment out the bundle from .zsh_plugins.txt
|
||||
if [[ -e "$bundlefile" ]]; then
|
||||
local tmpfile="${bundlefile}.antidote.tmp"
|
||||
$__adote_awkcmd -v pat="$bundle" '$0~"^[[:blank:]]*"pat{print "# " $0;next}1' <$bundlefile >|$tmpfile
|
||||
command cat "$tmpfile" > "$bundlefile"
|
||||
__antidote_del -f "$tmpfile"
|
||||
print "Bundle '$bundle' was commented out in '$bundlefile'."
|
||||
fi
|
||||
fi
|
||||
#}
|
||||
213
.antidote/functions/antidote-script
Normal file
213
.antidote/functions/antidote-script
Normal file
|
|
@ -0,0 +1,213 @@
|
|||
#!/bin/zsh
|
||||
|
||||
### Generate the Zsh script to load a plugin.
|
||||
#
|
||||
# usage: antidote script [-h|--help] [-k|--kind <kind>] [-p|--path <path>]
|
||||
# [-c|--conditional <func>] [-b|--branch <branch>]
|
||||
# [--pre <func>] [--post <func>]
|
||||
# [-a|--autoload <path>] <bundle>
|
||||
# <kind> : zsh,path,fpath,defer,clone,autoload
|
||||
# <path> : Relative path from the bundle root
|
||||
# <branch> : The git branch
|
||||
# <bundle> : A bundle can be a directory, a zsh script, or a git repo
|
||||
#
|
||||
|
||||
### Generate the Zsh script to load a plugin.
|
||||
#function antidote-script {
|
||||
emulate -L zsh; setopt local_options $_adote_funcopts
|
||||
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 o_fpath_rule
|
||||
zparseopts $_adote_zparopt_flags -- \
|
||||
h=o_help -help=h \
|
||||
a:=o_autoload -autoload:=a \
|
||||
b:=o_branch -branch:=b \
|
||||
k:=o_kind -kind:=k \
|
||||
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='^[=:]?(.+)$'
|
||||
[[ $o_kind[-1] =~ $re ]] && o_kind[-1]=$match
|
||||
[[ $o_autoload[-1] =~ $re ]] && o_autoload[-1]=$match
|
||||
[[ $o_path[-1] =~ $re ]] && o_path[-1]=$match
|
||||
[[ $o_cond[-1] =~ $re ]] && o_cond[-1]=$match
|
||||
[[ $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
|
||||
|
||||
# If no fpath_rule is set, use the zstyle
|
||||
if ! (( $#o_fpath_rule )); then
|
||||
local zstyle_fpath_rule
|
||||
zstyle -s ':antidote:fpath' rule 'zstyle_fpath_rule'
|
||||
[[ -z "$zstyle_fpath_rule" ]] || o_fpath_rule=($zstyle_fpath_rule)
|
||||
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
|
||||
fi
|
||||
local bundle_name=$(__antidote_bundle_name $bundle)
|
||||
|
||||
# replace ~/ with $HOME/
|
||||
if [[ "$bundle" == '~/'* ]]; then
|
||||
bundle=$HOME/${bundle#'~/'*}
|
||||
fi
|
||||
|
||||
# set the path to the bundle (repo or local)
|
||||
local bundle_path
|
||||
[[ -e "$bundle" ]] && bundle_path=$bundle || bundle_path=$(__antidote_bundle_dir $bundle)
|
||||
|
||||
# handle cloning repo bundles
|
||||
local bundle_type
|
||||
bundle_type="$(__antidote_bundle_type $bundle)"
|
||||
if [[ "$bundle_type" == (repo|url|sshurl) ]] && [[ ! -e "$bundle_path" ]]; then
|
||||
local giturl=$(__antidote_tourl $bundle)
|
||||
print -ru2 "# antidote cloning $bundle_name..."
|
||||
git clone --quiet --depth 1 --recurse-submodules --shallow-submodules $o_branch $giturl $bundle_path
|
||||
[[ $? -eq 0 ]] || return 1
|
||||
fi
|
||||
|
||||
# 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:bundle:${bundle}" defer-options 'dopts'
|
||||
[[ -n "$dopts" ]] && zsh_defer="zsh-defer $dopts"
|
||||
|
||||
# generate the script
|
||||
local -a script=()
|
||||
|
||||
# add pre-load function
|
||||
(( $#o_pre )) && script+=("$o_pre[-1]")
|
||||
|
||||
# handle defers
|
||||
local source_cmd="source"
|
||||
local zsh_defer_bundle
|
||||
zstyle -s ':antidote:defer' bundle 'zsh_defer_bundle' \
|
||||
|| zsh_defer_bundle='romkatv/zsh-defer'
|
||||
if [[ "$o_kind[-1]" == "defer" ]]; then
|
||||
source_cmd="${zsh_defer} source"
|
||||
script+=(
|
||||
'if ! (( $+functions[zsh-defer] )); then'
|
||||
"$(antidote-script $zsh_defer_bundle | __antidote_indent)"
|
||||
'fi'
|
||||
)
|
||||
fi
|
||||
|
||||
# Let's make the path a little nicer to deal with
|
||||
local print_bundle_path="$(__antidote_print_path "$bundle_path")"
|
||||
|
||||
# handle autoloading before sourcing
|
||||
if (( $#o_autoload )); then
|
||||
if [[ "$o_fpath_rule[-1]" == prepend ]]; then
|
||||
script+=("fpath=( ${print_bundle_path}/${o_autoload[-1]} \$fpath )")
|
||||
script+=("builtin autoload -Uz \$fpath[1]/*(N.:t)")
|
||||
else
|
||||
script+=("fpath+=( ${print_bundle_path}/${o_autoload[-1]} )")
|
||||
script+=("builtin autoload -Uz \$fpath[-1]/*(N.:t)")
|
||||
fi
|
||||
fi
|
||||
|
||||
# generate load script
|
||||
bundle_type="$(__antidote_bundle_type $bundle_path)"
|
||||
local fpath_script
|
||||
if [[ "$o_fpath_rule[-1]" == prepend ]]; then
|
||||
fpath_script="fpath=( $print_bundle_path \$fpath )"
|
||||
else
|
||||
fpath_script="fpath+=( $print_bundle_path )"
|
||||
fi
|
||||
|
||||
if [[ "$o_kind[-1]" == fpath ]]; then
|
||||
# fpath
|
||||
script+="$fpath_script"
|
||||
elif [[ "$o_kind[-1]" == path ]]; then
|
||||
# path
|
||||
script+="export PATH=\"$print_bundle_path:\$PATH\""
|
||||
elif [[ "$o_kind[-1]" == autoload ]]; then
|
||||
# autoload
|
||||
script+=("$fpath_script")
|
||||
if [[ "$o_fpath_rule[-1]" == prepend ]]; then
|
||||
script+=("builtin autoload -Uz \$fpath[1]/*(N.:t)")
|
||||
else
|
||||
script+=("builtin autoload -Uz \$fpath[-1]/*(N.:t)")
|
||||
fi
|
||||
else
|
||||
if zstyle -t ":antidote:bundle:$bundle" zcompile; then
|
||||
__antidote_bundle_zcompile $bundle_path
|
||||
fi
|
||||
if [[ $bundle_type == file ]]; then
|
||||
script+="$source_cmd $print_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
|
||||
if (( $#o_path )); then
|
||||
initfiles=($bundle_path/${bundle_path:t}.plugin.zsh)
|
||||
else
|
||||
initfiles=($bundle_path/${bundle_name:t}.plugin.zsh)
|
||||
fi
|
||||
fi
|
||||
script+="$fpath_script"
|
||||
local print_initfile
|
||||
for initfile in $initfiles; do
|
||||
print_initfile="$(__antidote_print_path "$initfile")"
|
||||
script+="$source_cmd $print_initfile"
|
||||
done
|
||||
fi
|
||||
fi
|
||||
|
||||
# add post-load function
|
||||
if (( $#o_post )); then
|
||||
if [[ "$o_kind[-1]" == "defer" ]]; then
|
||||
script+=("${zsh_defer} $o_post[-1]")
|
||||
else
|
||||
script+=("$o_post[-1]")
|
||||
fi
|
||||
fi
|
||||
|
||||
# mark bundle as loaded
|
||||
# script+="zstyle ':antidote:bundle:${bundle_name}' loaded yes"
|
||||
|
||||
# wrap conditional
|
||||
if [[ -n "$o_cond[-1]" ]]; then
|
||||
print "if $o_cond[-1]; then"
|
||||
printf " %s\n" $script
|
||||
print "fi"
|
||||
else
|
||||
printf "%s\n" $script
|
||||
fi
|
||||
#}
|
||||
94
.antidote/functions/antidote-update
Normal file
94
.antidote/functions/antidote-update
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
#!/bin/zsh
|
||||
|
||||
### Update antidote and its cloned bundles.
|
||||
#
|
||||
# usage: antidote update [-h|--help]
|
||||
#
|
||||
#function antidote-update {
|
||||
0=${(%):-%x}
|
||||
emulate -L zsh; setopt local_options $_adote_funcopts
|
||||
|
||||
local o_help o_self o_bundles
|
||||
zparseopts $_adote_zparopt_flags -- \
|
||||
h=o_help -help=h \
|
||||
s=o_self -self=s \
|
||||
b=o_bundles -bundles=b ||
|
||||
return 1
|
||||
|
||||
if (( $#o_help )); then
|
||||
antidote-help update
|
||||
return
|
||||
fi
|
||||
|
||||
# colors
|
||||
local green normal
|
||||
if [[ $TERM = *256color* || $TERM = *rxvt* ]]; then
|
||||
if (( $+commands[tput] )); then
|
||||
green=$(tput setaf 2)
|
||||
normal=$(tput sgr0)
|
||||
else
|
||||
green=$'\E[32m'
|
||||
normal=$'\E[0m'
|
||||
fi
|
||||
fi
|
||||
|
||||
if (( $#o_bundles )) || ! (( $#o_self )); then
|
||||
print "Updating bundles..."
|
||||
local bundledir url repo
|
||||
|
||||
# remove zcompiled files
|
||||
__antidote_del -rf -- $(antidote-home)/**/*.zwc(N)
|
||||
|
||||
# remove check file
|
||||
local loadable_check_path="$(antidote-home)/.antidote.load"
|
||||
[[ -r "$loadable_check_path" ]] && __antidote_del -- "$loadable_check_path"
|
||||
|
||||
# update all bundles
|
||||
for bundledir in $(antidote-list --dirs); do
|
||||
url=$(git -C "$bundledir" config remote.origin.url)
|
||||
repo="${url:h:t}/${${url:t}%.git}"
|
||||
print "antidote: checking for updates: $url"
|
||||
() {
|
||||
local oldsha=$(git -C "$1" rev-parse --short HEAD)
|
||||
git -C "$1" pull --quiet --ff --rebase --autostash
|
||||
git -C "$1" submodule --quiet sync --recursive
|
||||
git -C "$1" submodule --quiet update --init --recursive --depth 1
|
||||
local newsha=$(git -C "$1" rev-parse --short HEAD)
|
||||
if [[ $oldsha != $newsha ]]; then
|
||||
print "${green}antidote: updated: $2 ${oldsha} -> ${newsha}${normal}"
|
||||
git -C "$1" --no-pager log --oneline --ancestry-path ${oldsha}..${newsha} 2>/dev/null
|
||||
fi
|
||||
|
||||
# recompile bundles
|
||||
if zstyle -t ":antidote:bundle:$repo" zcompile; then
|
||||
__antidote_bundle_zcompile $bundledir
|
||||
fi
|
||||
} "$bundledir" "$url" &
|
||||
done
|
||||
print "Waiting for bundle updates to complete..."
|
||||
print ""
|
||||
wait
|
||||
print "${green}Bundle updates complete.${normal}"
|
||||
print ""
|
||||
fi
|
||||
|
||||
# update antidote
|
||||
if (( $#o_self )) || ! (( $#o_bundles )); then
|
||||
print "Updating antidote..."
|
||||
if [[ -d "${0:A:h:h}/.git" ]]; then
|
||||
git -C "${0:A:h:h}" pull --quiet --ff --rebase --autostash
|
||||
print "antidote self-update complete.\n"
|
||||
|
||||
# setup antidote again
|
||||
(( $+functions[__antidote_setup] )) && unfunction __antidote_setup
|
||||
builtin autoload -Uz ${0:A:h}/__antidote_setup
|
||||
__antidote_setup
|
||||
|
||||
# show antidote version
|
||||
antidote -v
|
||||
else
|
||||
print "Self updating is disabled in this build."
|
||||
print "Use your OS package manager to update antidote itself."
|
||||
fi
|
||||
fi
|
||||
#}
|
||||
Loading…
Add table
Add a link
Reference in a new issue