Skip to content

Commit 0504a88

Browse files
authored
Merge pull request #212 from mattmc3/v1.9.8-beta
v1.9.8
2 parents 9be3256 + c926fb8 commit 0504a88

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+877
-224
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 1.9.7
2+
current_version = 1.9.8
33
parse = v?(?P<major>\d+)\.(?P<minor>\d+)\.(?P<revision>\d+)
44
serialize = {major}.{minor}.{revision}
55

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: test-zsh-5.4.2
2+
3+
on:
4+
push:
5+
pull_request:
6+
workflow_dispatch:
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v3
13+
- uses: actions/checkout@v3
14+
with:
15+
repository: "aureliojargas/clitest"
16+
path: bin/clitest
17+
- run: |
18+
sudo apt update
19+
sudo apt install -y wget build-essential libncursesw5-dev
20+
wget https://sourceforge.net/projects/zsh/files/zsh/5.4.2/zsh-5.4.2.tar.xz
21+
tar -xf zsh-5.4.2.tar.xz
22+
cd zsh-5.4.2
23+
./configure --with-tcsetpgrp
24+
make
25+
sudo make install
26+
- run: |
27+
which zsh
28+
zsh --version
29+
name: Verify Zsh Installation
30+
- run: |
31+
export PATH=$GITHUB_WORKSPACE/bin/clitest:$PATH
32+
export ZSH_BINARY=/usr/local/bin/zsh
33+
make test

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# antidote
22

33
[![MIT License](https://img.shields.io/badge/license-MIT-007EC7.svg)](/LICENSE)
4-
![version](https://img.shields.io/badge/version-v1.9.7-df5e88)
4+
![version](https://img.shields.io/badge/version-v1.9.8-df5e88)
55

66
<a title="GetAntidote"
77
href="https://antidote.sh"

functions/__antidote_bundle_name

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
local parts=(${(ps./.)bundle})
1313
print ${parts[-2]}/${parts[-1]}
1414
else
15-
print $bundle | sed -e "s|^\~/|$HOME/|" -e "s|^$HOME|\$HOME|"
15+
# Replace ~ and $HOME with \$HOME
16+
bundle=${bundle/#\~\//\$HOME/}
17+
bundle=${bundle/#$HOME/\$HOME}
18+
print -r -- "$bundle"
1619
fi
1720
#}

functions/__antidote_del

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,16 @@
2020

2121
(( $# > 0 )) || return 1
2222

23+
local tmpdir
24+
if [[ -n "$TMPDIR" && (( -d "$TMPDIR" && -w "$TMPDIR" ) || ! ( -d /tmp && -w /tmp )) ]]; then
25+
tmpdir="${TMPDIR%/}"
26+
else
27+
tmpdir="/tmp"
28+
fi
29+
2330
for p in $@; do
2431
p="${p:a}"
25-
if [[ "$p" != $HOME/* ]] && [[ "$p" != ${TMPDIR:-/tmp}/* ]]; then
32+
if [[ "$p" != ${HOME}/* ]] && [[ "$p" != ${tmpdir}/* ]]; then
2633
print -ru2 -- "antidote: Blocked attempt to rm path: '$p'."
2734
return 1
2835
fi

functions/__antidote_filter_defers

Lines changed: 0 additions & 13 deletions
This file was deleted.

functions/__antidote_mktemp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/zsh
2+
3+
### Create a cross-platform temporary directory/file for antidote.
4+
#
5+
# usage: __antidote_mktemp [-d] [-f suffix]
6+
# -d Create a directory rather than a file
7+
# -s Use this for the temp file/dir
8+
#
9+
# Returns the path of created temp directory/file.
10+
#
11+
#function __antidote_mktemp {
12+
emulate -L zsh; setopt local_options $_adote_funcopts
13+
14+
local -a o_dir o_suffix
15+
zparseopts $_adote_zparopt_flags -- d=o_dir s:=o_suffix
16+
17+
# Set the appropriate temp directory (cargo cult code from p10k)
18+
local tmpbase
19+
if [[ -n "$TMPDIR" && (( -d "$TMPDIR" && -w "$TMPDIR" ) || ! ( -d /tmp && -w /tmp )) ]]; then
20+
tmpbase="${TMPDIR%/}"
21+
else
22+
tmpbase="/tmp"
23+
fi
24+
25+
# Create the pattern with PID
26+
local pattern="antidote.$$"
27+
28+
# Add suffix if provided with -s
29+
if (( $#o_suffix )) && [[ -n "${o_suffix[-1]}" ]]; then
30+
pattern="${pattern}.${o_suffix[-1]}"
31+
fi
32+
33+
# Add random chars
34+
pattern="${pattern}.XXXXXXXXXX"
35+
36+
# Create temp directory or file
37+
if (( $#o_dir )); then
38+
command mktemp -d "${tmpbase}/${pattern}"
39+
else
40+
command mktemp "${tmpbase}/${pattern}"
41+
fi
42+
#}

functions/__antidote_parse_bundles

Lines changed: 53 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,63 @@
33
### Parse antidote's bundle DSL.
44
#function __antidote_parse_bundles {
55
emulate -L zsh; setopt local_options $_adote_funcopts
6-
$__adote_awkcmd '
7-
BEGIN { RS="[\r\n]" }
86

9-
# skip comments and empty lines
10-
/^ *$/ || /^ *#/ {next}
7+
# Declare vars
8+
local bundle_str bundle_repr collected_input err lineno=0 skip_load_defer=0
9+
local key val
10+
local -a bundles
11+
local -A bundle
1112

12-
# strip trailing comments
13-
{ sub(/[ \t]#.*$/,"",$0) }
13+
# Get piped/passed bundles
14+
collected_input="$(__antidote_collect_input "$@")"
15+
if [[ -n "$collected_input" ]]; then
16+
bundles=( "${(@f)collected_input}" )
17+
else
18+
bundles=()
19+
fi
20+
if ! (( $#bundles )) ; then
21+
print -ru2 -- "antidote: error: bundle argument expected"
22+
return 1
23+
fi
1424

15-
# escape leading $ variables
16-
{ sub(/^\$/,"\\$",$0) }
25+
# Loop through bundles
26+
for bundle_str in $bundles; do
27+
(( lineno += 1 ))
1728

18-
# handle extension functionality (eg :use ohmyzsh)
19-
$1~/^:/ {
20-
sub(/^:/,"",$1)
21-
printf "antidote-script-" $1
22-
for (i=2; i<=NF; i++) {
23-
printf " %s",$i
24-
}
25-
printf "\n"
26-
next
27-
}
29+
# Parse the bundle.
30+
bundle_repr=$(__antidote_parser "$bundle_str"); err=$?
31+
if [[ -z "$bundle_repr" ]]; then
32+
continue
33+
elif [[ "$err" -ne 0 ]]; then
34+
print -ru2 -- "antidote: Bundle parser error on line ${lineno}: '$bundle_str'"
35+
return 1
36+
fi
37+
38+
# Turn the typeset repr into the bundle assoc_arr
39+
eval "$bundle_repr"
2840

2941
# move flags to front and call antidote-script
30-
{
31-
sub(/ #.*$/,"",$0)
32-
printf "antidote-script"
33-
for (i=2; i<=NF; i++) {
34-
sub(/^/,"--",$i)
35-
sub(/:/," ",$i)
36-
printf " %s",$i
37-
}
38-
printf " %s\n",$1
39-
}
40-
' "$@"
42+
print -rn -- "antidote-script"
43+
for key in ${(ok)bundle}; do
44+
[[ "$key" != name ]] && [[ "$key" != '_'* ]] || continue
45+
val="${bundle[$key]}"
46+
printf ' --%s %s' $key $val
47+
done
48+
49+
# Add flag for first defer
50+
if [[ "${bundle[kind]}" == "defer" ]]; then
51+
if [[ "$skip_load_defer" -eq 0 ]]; then
52+
skip_load_defer=1
53+
else
54+
printf ' --skip-load-defer'
55+
fi
56+
fi
57+
58+
# Escape leading '$' variables
59+
if [[ "${bundle[name]}" == '$'* ]]; then
60+
printf ' \$%s\n' "${bundle[name]#\$}"
61+
else
62+
printf ' %s\n' "${bundle[name]}"
63+
fi
64+
done
4165
#}

functions/__antidote_parser

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#!/bin/zsh
2+
3+
### Parse antidote's bundle DSL to an associative array.
4+
# Example:
5+
# __antidote_parser 'foo/bar path:plugins/baz kind:fpath pre:myprecmd # comment'
6+
# typeset -A bundle=( [kind]=fpath [path]=plugins/baz [pre]=myprecmd [name]=foo/bar )
7+
#
8+
# Notes:
9+
# bundle_str : antidote DSL syntax
10+
# bundle : assoc array representation
11+
# bundle_repr : Zsh serialization of the bundle assoc arrary
12+
#
13+
# Metadata:
14+
# _repodir : The clone destination dir
15+
# _type : The type of bundle (url, repo, path, ?)
16+
# _repo : The user/repo short form of the URL
17+
# _url : The git repo URL
18+
#
19+
#function __antidote_parser {
20+
emulate -L zsh; setopt local_options $_adote_funcopts
21+
local MATCH MBEGIN MEND; local -a match mbegin mend # appease 'warn_create_global'
22+
local bundle_str bundle_var bundle_repr gitsite str pair key value
23+
local -a kvpairs parts
24+
local -A bundle
25+
26+
bundle_str="$1"
27+
bundle_var="${2:-bundle}"
28+
29+
# Allow the user to override the default git site if they really want to
30+
zstyle -s ':antidote:gitremote' url 'gitsite' \
31+
|| gitsite='https://github.com'
32+
gitsite="${gitsite%/}"
33+
34+
# Remove anything after the first '#'
35+
bundle_str=${bundle_str%%\#*}
36+
# Trim spaces
37+
bundle_str=${${bundle_str/#[[:space:]]#}/%[[:space:]]#}
38+
# Skip empty bundle strings
39+
[[ -z "$bundle_str" ]] && return 0
40+
# 1st field gets a 'name:' prefix so we can treat everything as key:val pairs
41+
bundle_str="name:${bundle_str}"
42+
43+
# Split line into key-value pairs with quoting
44+
kvpairs=(${(Q)${(z)bundle_str}})
45+
for pair in "${kvpairs[@]}"; do
46+
key=${pair%%:*} # Extract key (before first ':')
47+
if [[ "$pair" == *:* ]]; then
48+
value=${pair#*:} # Extract value (after first ':')
49+
else
50+
value=
51+
fi
52+
bundle[$key]=$value
53+
done
54+
55+
# Enhance the bundle with metadata fields. Metadata fields begin with an underscore
56+
# since those will never be part of the DSL. Let's start with _type, which tells us
57+
# whether the bundle is a URL, a user/repo, or a path
58+
if [[ "$bundle[name]" == *://*/*/* || "$bundle[name]" == (ssh|git)@*:*/* ]]; then
59+
if [[ "$bundle[name]" == *://*/*/*/* || "$bundle[name]" == *@*:*/*/* ]]; then
60+
bundle[_type]="?"
61+
else
62+
bundle[_type]="url"
63+
fi
64+
elif [[ "$bundle[name]" == *('@'|':')* ]] ; then
65+
bundle[_type]="?" # bad URLs
66+
elif [[ "$bundle[name]" == ('~'|'$'|'.')* ]]; then
67+
bundle[_type]="path"
68+
elif [[ "$bundle[name]" == */* && "$bundle[name]" != */*/* ]]; then
69+
bundle[_type]="repo"
70+
elif [[ "$bundle[name]" == */* ]]; then
71+
bundle[_type]="path"
72+
else
73+
bundle[_type]="?"
74+
fi
75+
76+
# For git repos, we add a metadata field for the URL
77+
if [[ "$bundle[_type]" == url ]]; then
78+
str="$bundle[name]"
79+
str=${str%.git}
80+
str=${str:gs/\:/\/}
81+
parts=( ${(ps./.)str} )
82+
if [[ $#parts -gt 1 ]]; then
83+
bundle[_repo]="${parts[-2]}/${parts[-1]}"
84+
else
85+
bundle[_repo]="$str"
86+
fi
87+
bundle[_url]="$bundle[name]"
88+
elif [[ "$bundle[_type]" == repo ]]; then
89+
bundle[_repo]="${bundle[name]}"
90+
bundle[_url]="${gitsite}/${bundle[name]}"
91+
fi
92+
93+
# If there's a git URL, we also need to set the _repodir
94+
if [[ -v bundle[_url] ]]; then
95+
# TODO: Remove for antidote 2.0
96+
if zstyle -t ':antidote:compatibility-mode' 'antibody' || ! zstyle -t ':antidote:bundle' use-friendly-names; then
97+
# sanitize URL for safe use as a dir name
98+
# ex: $ANTIDOTE_HOME/https-COLON--SLASH--SLASH-github.com-SLASH-zsh-users-SLASH-zsh-autosuggestions
99+
str="$bundle[_url]"
100+
str=${str%.git}
101+
str=${str:gs/\@/-AT-}
102+
str=${str:gs/\:/-COLON-}
103+
str=${str:gs/\//-SLASH-}
104+
bundle[_repodir]="$str"
105+
else
106+
bundle[_repodir]="$bundle[_repo]"
107+
fi
108+
fi
109+
110+
# Print the parsed bundle assoc arr using whatever bundle_var the user wants
111+
bundle_repr="$(declare -p bundle)"
112+
bundle_repr="typeset -A ${bundle_var}=${bundle_repr#*=}"
113+
114+
# Sanity check that I probably don't need.
115+
if [[ ! "$bundle_repr" =~ "^typeset\ -A\ ${bundle_var}=" ]]; then
116+
print -ru2 -- "antidote: Unable to parse bundle string: '$bundle_str'."
117+
return 1
118+
fi
119+
120+
# Return/print the result.
121+
typeset -g REPLY="$bundle_repr"
122+
print -r -- "$REPLY"
123+
#}

functions/__antidote_print_path

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#!/bin/zsh
22
### Pretty print a path
3-
3+
#function __antidote_print_path {
44
if zstyle -t ':antidote:compatibility-mode' 'antibody'; then
5-
echo "$1"
5+
print -r -- "$1"
66
else
7-
echo "$1" | sed -e "s|^$HOME/|\$HOME/|"
7+
print -r -- "${1/#$HOME/\$HOME}"
88
fi
9+
#}

0 commit comments

Comments
 (0)