mirror of
https://github.com/jorgebucaran/fisher
synced 2024-10-05 09:32:37 +02:00
Add line breaks and run other post processing on the JSON response
when updating the index for ls-remote. Allow ls-remote to accept a key and always print record if it matches the plugin's name. Works with the format string too. Close #234, #236, #238
This commit is contained in:
parent
a7d5e707d9
commit
097ed41f00
1 changed files with 116 additions and 52 deletions
168
fisher.fish
168
fisher.fish
|
@ -73,7 +73,6 @@ function fisher
|
||||||
end
|
end
|
||||||
|
|
||||||
set -l cmd
|
set -l cmd
|
||||||
set -l value
|
|
||||||
|
|
||||||
switch "$argv[1]"
|
switch "$argv[1]"
|
||||||
case i install
|
case i install
|
||||||
|
@ -96,11 +95,6 @@ function fisher
|
||||||
set -e argv[1]
|
set -e argv[1]
|
||||||
set cmd "ls-remote"
|
set cmd "ls-remote"
|
||||||
|
|
||||||
switch "$argv[1]"
|
|
||||||
case --format\*
|
|
||||||
set value (printf "%s\n" "$argv" | command sed 's|^--[^= ]*[= ]\(.*\)|\1|')
|
|
||||||
end
|
|
||||||
|
|
||||||
case h help
|
case h help
|
||||||
set -e argv[1]
|
set -e argv[1]
|
||||||
__fisher_help $argv
|
__fisher_help $argv
|
||||||
|
@ -218,7 +212,21 @@ function fisher
|
||||||
end
|
end
|
||||||
|
|
||||||
case ls-remote
|
case ls-remote
|
||||||
__fisher_list_remote "$value"
|
set -l format
|
||||||
|
|
||||||
|
if test ! -z "$argv"
|
||||||
|
switch "$argv[1]"
|
||||||
|
case --format\*
|
||||||
|
set format (printf "%s\n" "$argv[1]" | command sed 's|^--[^= ]*[= ]\(.*\)|\1|')
|
||||||
|
set -e argv[1]
|
||||||
|
end
|
||||||
|
|
||||||
|
if test -z "$format"
|
||||||
|
set format "%info\n%url\n"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
__fisher_list_remote "$format" $argv
|
||||||
|
|
||||||
case rm
|
case rm
|
||||||
if test -z "$items"
|
if test -z "$items"
|
||||||
|
@ -819,7 +827,28 @@ function __fisher_remote_index_update
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
fish -c "curl -s 'https://api.github.com/orgs/fisherman/repos?per_page=100' > '$index'" &
|
fish -c "
|
||||||
|
|
||||||
|
curl -s 'https://api.github.com/orgs/fisherman/repos?per_page=100' | awk -v ORS='' '
|
||||||
|
|
||||||
|
{
|
||||||
|
gsub(/[{}\[\]]|^[\t ]*/, \"\")
|
||||||
|
|
||||||
|
} //
|
||||||
|
|
||||||
|
' | awk '
|
||||||
|
|
||||||
|
{
|
||||||
|
n = split(\$0, a, /,\"/)
|
||||||
|
|
||||||
|
for (i = 1; i <= n; i++) {
|
||||||
|
gsub(/\"/, \"\", a[i])
|
||||||
|
print(a[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
' > '$index'
|
||||||
|
" &
|
||||||
|
|
||||||
__fisher_jobs_await (__fisher_jobs_get -l)
|
__fisher_jobs_await (__fisher_jobs_get -l)
|
||||||
|
|
||||||
|
@ -829,7 +858,7 @@ function __fisher_remote_index_update
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function __fisher_list_remote -a format
|
function __fisher_list_remote -a format key
|
||||||
set -l index "$fisher_cache/.index.json"
|
set -l index "$fisher_cache/.index.json"
|
||||||
|
|
||||||
if not __fisher_remote_index_update
|
if not __fisher_remote_index_update
|
||||||
|
@ -854,30 +883,42 @@ function __fisher_list_remote -a format
|
||||||
|
|
||||||
set -l config "$fisher_config"/*
|
set -l config "$fisher_config"/*
|
||||||
|
|
||||||
command awk -v format_s="$format" -v config="$config" '
|
command awk -v format_s="$format" -v config="$config" -v key="$key" '
|
||||||
|
|
||||||
function qsort(A, L, R, pivot, j, i, t) {
|
function quicksort(list, lo, hi, pivot, j, i, t) {
|
||||||
pivot = j = i = t
|
pivot = j = i = t
|
||||||
if (L >= R) {
|
|
||||||
|
if (lo >= hi) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
pivot = L
|
|
||||||
i = L
|
pivot = lo
|
||||||
j = R
|
i = lo
|
||||||
|
j = hi
|
||||||
|
|
||||||
while (i < j) {
|
while (i < j) {
|
||||||
while (A[i] <= A[pivot] && i < R) i++
|
while (list[i] <= list[pivot] && i < hi) {
|
||||||
while (A[j] > A[pivot]) j--
|
i++
|
||||||
|
}
|
||||||
|
|
||||||
|
while (list[j] > list[pivot]) {
|
||||||
|
j--
|
||||||
|
}
|
||||||
|
|
||||||
if (i < j) {
|
if (i < j) {
|
||||||
t = A[i]
|
t = list[i]
|
||||||
A[i] = A[j]
|
list[i] = list[j]
|
||||||
A[j] = t
|
list[j] = t
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
t = A[pivot]
|
|
||||||
A[pivot] = A[j]
|
t = list[pivot]
|
||||||
A[j] = t
|
|
||||||
qsort(A, L, j - 1)
|
list[pivot] = list[j]
|
||||||
qsort(A, j + 1, R)
|
list[j] = t
|
||||||
|
|
||||||
|
quicksort(list, lo, j - 1)
|
||||||
|
quicksort(list, j + 1, hi)
|
||||||
}
|
}
|
||||||
|
|
||||||
function basename(s, n, a) {
|
function basename(s, n, a) {
|
||||||
|
@ -885,8 +926,8 @@ function __fisher_list_remote -a format
|
||||||
return a[n]
|
return a[n]
|
||||||
}
|
}
|
||||||
|
|
||||||
function in_config(item, i) {
|
function plugin_is_config(item, i) {
|
||||||
for (i = 1; i <= config_n; i++) {
|
for (i = 1; i <= config_count; i++) {
|
||||||
if (item == config_a[i]) {
|
if (item == config_a[i]) {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
@ -895,7 +936,11 @@ function __fisher_list_remote -a format
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
function print_record_with_format(name, stars, url, info, fmt) {
|
function plugin_is_blacklisted(item) {
|
||||||
|
return (item ~ /^awesome-fish|^fisherman|^index|^logo|^taof/)
|
||||||
|
}
|
||||||
|
|
||||||
|
function record_printf(fmt, name, info, url, stars) {
|
||||||
gsub(/%name/, name, fmt)
|
gsub(/%name/, name, fmt)
|
||||||
gsub(/%stars/, stars, fmt)
|
gsub(/%stars/, stars, fmt)
|
||||||
gsub(/%url/, url, fmt)
|
gsub(/%url/, url, fmt)
|
||||||
|
@ -904,55 +949,74 @@ function __fisher_list_remote -a format
|
||||||
printf(fmt)
|
printf(fmt)
|
||||||
}
|
}
|
||||||
|
|
||||||
function json_get_field(s) {
|
function field_parse(s) {
|
||||||
if ($0 ~ "^" s ":") {
|
if ($0 ~ "^" s ":") {
|
||||||
return substr($0, length(s) + 3)
|
return substr($0, length(s) + 3)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BEGIN {
|
BEGIN {
|
||||||
config_n = split(config, config_a)
|
config_count = split(config, config_a)
|
||||||
|
|
||||||
for (i = 1; i <= config_n; i++) {
|
for (i = 1; i <= config_count; i++) {
|
||||||
config_a[i] = basename(config_a[i])
|
config_a[i] = basename(config_a[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
gsub(/[\[\],{}"]|^[\t ]+/, "")
|
s = field_parse("name")
|
||||||
|
if (s != "") {
|
||||||
s = json_get_field("name")
|
name = s
|
||||||
name = s != "" ? s : name
|
# next
|
||||||
|
}
|
||||||
s = json_get_field("description")
|
s = field_parse("description")
|
||||||
info = s != "" ? s : info
|
if (s != "") {
|
||||||
|
info = s
|
||||||
s = json_get_field("stargazers_count")
|
# next
|
||||||
stars = s != "" ? s : stars
|
}
|
||||||
|
s = field_parse("stargazers_count")
|
||||||
if (name != "" && info != "" && stars != "" && !in_config(name)) {
|
if (s != "") {
|
||||||
if (name !~ /^awesome-fish|^fisherman|^index|logo/) {
|
stars = s
|
||||||
info = (info == "null") ? "No description." : info
|
|
||||||
records[++record_index] = name ";" info ";" stars
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# name = (s = field_parse("name")) ? s : name
|
||||||
|
# info = (s = field_parse("description")) ? s : info
|
||||||
|
# stars = (s = field_parse("stargazers_count")) ? s : stars
|
||||||
|
|
||||||
|
if (name && info && stars != "") {
|
||||||
|
records[++record_count] = name ";" stars ";" info
|
||||||
name = info = stars = ""
|
name = info = stars = ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
END {
|
END {
|
||||||
qsort(records, 1, record_index)
|
quicksort(records, 1, record_count)
|
||||||
|
|
||||||
for (i = 1; i <= record_index; i++) {
|
for (i = 1; i <= record_count; i++) {
|
||||||
n = split(records[i], r, ";")
|
split(records[i], r, ";")
|
||||||
|
|
||||||
if (n == 3) {
|
name = r[1]
|
||||||
print_record_with_format(r[1], r[2], "github.com/fisherman/"r[1], r[3], format_s)
|
|
||||||
|
if (key != "" && key != name) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
stars = r[2]
|
||||||
|
info = r[3] (substr($0, length($0), 1) == "." ? "" : ".")
|
||||||
|
url = "github.com/fisherman/" name
|
||||||
|
|
||||||
|
if (key == name) {
|
||||||
|
record_printf(format_s, name, info, url, stars)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!plugin_is_config(r[1]) && !plugin_is_blacklisted(r[1])) {
|
||||||
|
record_printf(format_s, name, info, url, stars)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
' < "$index" | column $column_options
|
' < "$index" | command column $column_options
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue