mirror of
https://github.com/jorgebucaran/fisher
synced 2024-09-18 15:27:38 +02:00
Fork awk only once, simplify.
This commit is contained in:
parent
f6519e9ad4
commit
d6fd6be951
1 changed files with 25 additions and 26 deletions
|
@ -4,6 +4,7 @@ function fisher_search -d "Search Plugins"
|
||||||
set -l index
|
set -l index
|
||||||
set -l join "||"
|
set -l join "||"
|
||||||
set -l quiet 0
|
set -l quiet 0
|
||||||
|
set -l stdout /dev/stdout
|
||||||
|
|
||||||
getopts $argv | while read -l 1 2 3
|
getopts $argv | while read -l 1 2 3
|
||||||
switch "$1"
|
switch "$1"
|
||||||
|
@ -59,6 +60,7 @@ function fisher_search -d "Search Plugins"
|
||||||
|
|
||||||
case q quiet
|
case q quiet
|
||||||
set quiet 1
|
set quiet 1
|
||||||
|
set stdout /dev/null
|
||||||
|
|
||||||
case h
|
case h
|
||||||
printf "Usage: fisher search [<plugins>] [--and|--or] [--quiet] [--help]\n\n"
|
printf "Usage: fisher search [<plugins>] [--and|--or] [--quiet] [--help]\n\n"
|
||||||
|
@ -86,10 +88,14 @@ function fisher_search -d "Search Plugins"
|
||||||
end
|
end
|
||||||
|
|
||||||
if test $fisher_last_update -gt $fisher_update_interval -o ! -f $index
|
if test $fisher_last_update -gt $fisher_update_interval -o ! -f $index
|
||||||
debug "Update index"
|
debug "Update index start"
|
||||||
|
|
||||||
if spin "__fisher_index_update" --error=/dev/null
|
if spin "__fisher_index_update" --error=/dev/null
|
||||||
|
debug "Update index success"
|
||||||
|
|
||||||
__fisher_complete_reset
|
__fisher_complete_reset
|
||||||
|
else
|
||||||
|
debug "Update index fail"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -99,15 +105,14 @@ function fisher_search -d "Search Plugins"
|
||||||
set -e fields[-1]
|
set -e fields[-1]
|
||||||
set -e query[-1]
|
set -e query[-1]
|
||||||
|
|
||||||
|
set -l options -v OFS=';'
|
||||||
|
|
||||||
if test -z "$fields[1]"
|
if test -z "$fields[1]"
|
||||||
set fields '$0'
|
set fields '$0'
|
||||||
|
set options -v OFS='\n' -v ORS='\n'
|
||||||
end
|
end
|
||||||
|
|
||||||
awk -F'\n' -v RS='' -v OFS=';' (
|
awk -v FS='\n' -v RS='' $options "
|
||||||
if test "$fields" = '$0'
|
|
||||||
printf "%s\nORS=%s" -v '\\n\\n'
|
|
||||||
end
|
|
||||||
) "
|
|
||||||
|
|
||||||
function tags(tag, _list) {
|
function tags(tag, _list) {
|
||||||
if (!tag) {
|
if (!tag) {
|
||||||
|
@ -126,9 +131,12 @@ function fisher_search -d "Search Plugins"
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
/^ *#/ { next } {
|
{
|
||||||
delete tag_list
|
delete tag_list
|
||||||
if (\$4) split(\$4, tag_list, \" \")
|
|
||||||
|
if (\$4) {
|
||||||
|
split(\$4, tag_list, \" \")
|
||||||
|
}
|
||||||
|
|
||||||
name = \$1
|
name = \$1
|
||||||
url = \$2
|
url = \$2
|
||||||
|
@ -136,25 +144,16 @@ function fisher_search -d "Search Plugins"
|
||||||
author = \$5
|
author = \$5
|
||||||
}
|
}
|
||||||
|
|
||||||
$query { print $fields } " $index ^ /dev/null | awk -v quiet=$quiet '
|
$query {
|
||||||
|
if (has_records) {
|
||||||
!/^ *$/ { hasRecords = 1 } {
|
print \"\"
|
||||||
if (quiet) {
|
|
||||||
exit !hasRecords
|
|
||||||
} else {
|
|
||||||
records[NR] = $0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
END {
|
print $fields
|
||||||
for (i = 1; i <= NR; i++) {
|
has_records = 1
|
||||||
if (i == NR && records[i] ~ /^ *$/) {
|
}
|
||||||
break
|
|
||||||
}
|
|
||||||
print records[i]
|
|
||||||
}
|
|
||||||
|
|
||||||
exit !hasRecords
|
END { exit !has_records }
|
||||||
}
|
|
||||||
'
|
" $index > $stdout ^ /dev/null
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue