-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
196 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/bin/zsh | ||
|
||
__tags_for_cache() { | ||
local key | ||
|
||
for key in ${(k)zplugs} | ||
do | ||
echo "name:$key, $zplugs[$key]" | ||
done \ | ||
| awk -f "$ZPLUG_ROOT/src/share/cache.awk" | ||
} | ||
|
||
__load_cache() { | ||
local key | ||
|
||
$ZPLUG_USE_CACHE || return 2 | ||
if [[ -f $_ZPLUG_CACHE_FILE ]]; then | ||
&>/dev/null diff -b \ | ||
<( \ | ||
awk -f "$ZPLUG_ROOT/src/share/read_cache.awk" \ | ||
"$_ZPLUG_CACHE_FILE" \ | ||
) \ | ||
<( \ | ||
for key in ${(k)zplugs}; do \ | ||
echo "name:$key, $zplugs[$key]"; \ | ||
done \ | ||
| awk -f "$ZPLUG_ROOT/src/share/cache.awk" | ||
) | ||
|
||
case $status in | ||
0) | ||
# same | ||
source "$_ZPLUG_CACHE_FILE" | ||
return $status | ||
;; | ||
1) | ||
# differ | ||
;; | ||
2) | ||
# error | ||
__die "zplug: cache: something wrong\n" | ||
;; | ||
esac | ||
fi | ||
|
||
return 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
BEGIN { | ||
TAGS_SEP = ", "; | ||
} | ||
|
||
{ | ||
arr[NR] = reconstruct($0); | ||
} | ||
|
||
END { | ||
for (i in arr) | ||
print arr[i]; | ||
} | ||
|
||
function reconstruct(line, tags) { | ||
gsub(/, +/, TAGS_SEP, line) | ||
split(line, tags, TAGS_SEP); | ||
quick_sort(tags, 1, length(tags)); | ||
|
||
return join(tags, 1, length(tags), TAGS_SEP); | ||
} | ||
|
||
function quick_sort(array, left, right, i, j, tmp, pivot) { | ||
if (left < right) { | ||
i = left; | ||
j = right; | ||
pivot = array[int((left + right) / 2)]; | ||
while (i <= j) { | ||
while (array[i] < pivot) { | ||
i++; | ||
} | ||
while (array[j] > pivot) { | ||
j--; | ||
} | ||
if (i <= j) { | ||
tmp = array[i]; | ||
array[i] = array[j]; | ||
array[j] = tmp; | ||
i++; | ||
j--; | ||
} | ||
} | ||
quick_sort(array, left, j); | ||
quick_sort(array, i, right); | ||
} | ||
} | ||
|
||
function join(array, start, end, sep, result, i) { | ||
if (sep == "") { | ||
sep = " "; | ||
} else if (sep == SUBSEP) { | ||
sep = ""; | ||
} | ||
|
||
result = array[start]; | ||
for (i = start + 1; i <= end; i++) { | ||
result = result sep array[i]; | ||
} | ||
|
||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
BEGIN { | ||
KEY_SEP = ":"; | ||
TAGS_SEP = ", "; | ||
} | ||
|
||
{ | ||
arr[NR] = $0; | ||
} | ||
|
||
END { | ||
if (get_tag(arr, "junegunn/fzf-bin") != 0) | ||
exit 1; | ||
} | ||
|
||
function get_name(arr, tag, n, tags, i, name) { | ||
n = split(tag, tags, "#"); | ||
for (i in tags) { | ||
if (tags[i] ~ /\//) { | ||
name = tags[i]; | ||
break; | ||
} | ||
} | ||
return name; | ||
} | ||
|
||
function get_tag(line, tag, name, i, j, n, tags, line_tags, ret, key_and_value, key, value) { | ||
name = get_name(line, tag); | ||
if (name == "") { | ||
return 1; | ||
} | ||
n = split(tag, tags, "#"); | ||
|
||
for (i in line) { | ||
if (line[i] ~ "name" KEY_SEP name TAGS_SEP) { | ||
m = split(line[i], line_tags, TAGS_SEP); | ||
for (j in line_tags) { | ||
split(line_tags[j], key_and_value, KEY_SEP); | ||
key = key_and_value[1]; | ||
value = key_and_value[2]; | ||
if (n == 1) { | ||
ret[key] = value; | ||
} | ||
if (in_array(key, tags) == 0) { | ||
ret[key] = value; | ||
} | ||
} | ||
} | ||
} | ||
|
||
if (length(ret) == 0) | ||
return 1; | ||
|
||
for (key in ret) | ||
print key KEY_SEP ret[key]; | ||
} | ||
|
||
function in_array(e, arr, i) { | ||
for (i in arr) { | ||
if (arr[i] == e) | ||
return 0; | ||
} | ||
return 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
BEGIN { | ||
flag = 0; | ||
} | ||
|
||
{ | ||
if ($0 == "return 0") { | ||
flag = 1; | ||
next; | ||
} | ||
} | ||
|
||
flag { | ||
print $0; | ||
} |