2 # aur-search - search for AUR packages
3 [[ -v AUR_DEBUG
]] && set -o xtrace
5 AUR_LOCATION
=${AUR_LOCATION:-'https://aur.archlinux.org'}
6 PS4
='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
9 multiple
=section search_by
=name-desc sort_key
=Name
type=search mode
=query
17 # Interpret escapes with %b for "dumb" terminals (#1001)
18 printf "\e]8;;%s\e\\%b\e]8;;\e\\" "$uri" "$mesg"
22 # It is important to have a default value for every field, or
23 # parsing of the @tsv result might break.
24 # See: https://lists.gnu.org/archive/html/help-bash/2016-05/msg00041.html
25 # For arrays, individual elements have to be checked as well.
26 # See: https://gitlab.archlinux.org/archlinux/aurweb/-/issues/332
27 jq
-r --arg key
"$1" '
30 map(if . == "" then "-" else . end) | join(" ")
35 [.results[]] | sort_by(.[$key])[] | [
42 (.Keywords | sel_join),
43 (.License | sel_join),
50 (.FirstSubmitted | todate),
51 (.LastModified | todate),
52 (.Depends | sel_join),
53 (.MakeDepends | sel_join),
54 (.CheckDepends | sel_join),
55 (.OptDepends | sel_join)
81 while IFS
=$
'\t' read -r -a info
; do
82 printf "$BOLD%s:$ALL_OFF\\t%s\\n" "AUR URL" "$AUR_LOCATION/packages/${info[0]}"
84 for i
in "${!info[@]}"; do
85 printf "$BOLD%s:$ALL_OFF\\t%s\\n" "${desc[i]}" "${info[i]}"
88 # column(1) ignores empty lines (package delimitation)
94 local Name Version NumVotes Popularity Maintainer OutOfDate Description Url Link
96 while IFS
=$
'\t' read -r Name _ Version Description _ _ _ Maintainer NumVotes Popularity OutOfDate _
; do
99 *) printf -v OutOfDate
'(Out-of-date: %(%d %B %Y)T)' "$OutOfDate"
103 -) Maintainer
='(Orphaned) ' ;;
104 *) unset Maintainer
;;
107 # Unset LC_ALL to ensure it doesn't override LC_NUMERIC.
108 LC_ALL
='' LC_NUMERIC
=C
printf -v Popularity
'%.2f' "$Popularity"
110 Url
="${AUR_LOCATION}/packages/${Name}"
111 Link
="$(hyperlink "$Url" "${BLUE}aur/${ALL_OFF}${BOLD}${Name}")"
113 printf "%s ${GREEN}%s ${ALL_OFF}(+%s %s%%) ${RED}%s%s${ALL_OFF}\\n %s\\n" \
114 "$Link" "$Version" "$NumVotes" "$Popularity" "$Maintainer" "$OutOfDate" "$Description"
119 plain
>&2 'usage: %s [-adimnqrsv] [-k key] pkgname...' "$argv0"
123 source /usr
/share
/makepkg
/util
/message.sh
124 source /usr
/share
/makepkg
/util
/parseopts.sh
126 if [[ ! -v NO_COLOR
]] && [[ ! -v AUR_DEBUG
]]; then
127 # We use colored messages on both stdout and stderr, and these may
128 # be desired even if stdout is not connected to a terminal. (in
129 # particular, aur search foo | less -R, #585)
133 opt_short
='k:adimnqrsv'
134 opt_long
=('any' 'info' 'search' 'desc' 'maintainer' 'name' 'depends' 'verbose'
135 'makedepends' 'optdepends' 'checkdepends' 'key:' 'short' 'table' 'json')
136 opt_hidden
=('dump-options' 'raw' 'json-stdin')
138 if ! parseopts
"$opt_short" "${opt_long[@]}" "${opt_hidden[@]}" -- "$@"; then
141 set -- "${OPTRET[@]}"
153 search_by
=name-desc
;;
155 search_by
=maintainer
;;
161 search_by
=makedepends
;;
163 search_by
=optdepends
;;
165 search_by
=checkdepends
;;
177 shift; sort_key
=$1 ;;
179 printf -- '--%s\n' "${opt_long[@]}" ${AUR_DEBUG+"${opt_hidden[@]}"}
180 printf -- '%s' "${opt_short}" | sed 's/.:\?/-&\n/g'
187 if ! (( $# )) && ! [[ $mode == "stdin_json
" || $mode == "stdin_table
" ]]; then
191 # set format depending on query type (#319)
193 info) format=${format-long} ;;
194 search) format=${format-short} ;;
199 long) info() { info_long | column -ts $'\t' | sed -E 's/^-//; $d'; } ;;
200 short) info() { info_short; } ;;
201 table) info() { tee; } ;;
206 section) ;; # aur-query default
207 union) query_args+=('--any') ;;
212 aur query -t "$type" -b "$search_by" -e "${query_args[@]}" "$@
" | tabulate "$sort_key" | info
213 exit "${PIPESTATUS[0]}" ;;
215 aur query -t "$type" -b "$search_by" -e "${query_args[@]}" "$@
"
218 tabulate "$sort_key" | info
222 # vim: set et sw=4 sts=4 ft=sh: