#!/bin/bash shellfu import pretty uripecker() { # # Scan stdin for what looks like URI, ID or keyword # # Usage: # /dev/null & ## # process each pipe *async* by different filter # < "$maybe_uris" __uripecker__flt_uris > "$uris" & < "$maybe_ids" __uripecker__flt_ids | __uripecker__deref > "$uris_from_ids" & < "$maybe_exps" __uripecker__flt_exps | __uripecker__deref > "$uris_from_exps" & < "$maybe_tags" __uripecker__flt_tags | __uripecker__deref > "$uris_from_tags" & < "$maybe_kws" __uripecker__flt_kws | __uripecker__deref > "$uris_from_kws" & ## # print result *sync* in correct order # { cat "$uris" cat "$uris_from_ids" cat "$uris_from_exps" cat "$uris_from_tags" cat "$uris_from_kws" } | grep . # throw away empties; add missing LF rm -rf "$tmp" } __uripecker__map_lookup() { # # Look up query $1 in $Map # local key=${1,,} sed ' s/^ *// s/ *$// s/ *= */=/ ' <<<"$MapBody" \ | grep "^$key=" \ | cut -d= -f2- } __uripecker__deref() { # # Turn query (like "g hello" for google) to URI # local kw # keyword part, eg. "g" or "bug" local query # query part, eg. "hello+dolly" or "1234" local fmt # for queries: format string (from ini) to pass to printf while read -r kw query; do debug -v kw query fmt=$(__uripecker__map_lookup "$kw") || return 1 debug -v fmt #shellcheck disable=SC2059 printf "$fmt\n" "$(__uripecker__urlquote "$query")" done } __uripecker__flt_exps() { # # Hack expressions like bug = 123 out of the text # sed -e 's/(\d)\/dev/null \ | grep -qF 'Python 3.'; then __URIPECKER_PYBIN=python3 __URIPECKER_PYMOD=urllib.parse else __URIPECKER_PYBIN=python __URIPECKER_PYMOD=urllib fi } #shellfu module-version=__MKIT_PROJ_VERSION__