#!/bin/bash ffoo import inigrep ffoo import pretty __saturnin_urimagic__deref() { # # Turn keyword or query (like "g hello" for google) to URI # local line # input line, eg. "g hello dolly" or "bug 1234" local kw # keyword part, eg. "g" or "bug" local query # query part, eg. "hello dolly" or "1234" while read line; do line="$line " kw=${line%% *} query=${line#$kw } debug -v kw query if test -n "$query"; then local fmt=$(inigrep -j -1 -p www.query.${kw,,}) debug -v fmt printf "$fmt\n" "$query" else inigrep -j -1 -p www.bookmark.$kw fi done } __saturnin_urimagic__flt_exps() { # # Hack expressions like bug = 123 out of the text # sed -e 's/(\d)\&/dev/null ## # heat up and fill pipes # mkfifo maybe_uris maybe_ids maybe_exps maybe_tags maybe_kws \ uris uris_from_ids uris_from_exps uris_from_tags uris_from_kws cat | tee maybe_uris maybe_ids maybe_exps maybe_tags maybe_kws \ >/dev/null & ## # process each pipe *async* by different filter # < maybe_uris ${p}flt_uris > uris & < maybe_ids ${p}flt_ids | ${p}deref > uris_from_ids & < maybe_exps ${p}flt_exps | ${p}deref > uris_from_exps & < maybe_tags ${p}flt_tags | ${p}deref > uris_from_tags & < maybe_kws ${p}flt_kws | ${p}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 popd >&/dev/null rm -rf $d }