#!/bin/bash ### this script reads a config from stdin ### and does multiple urimatches on the uri argument. ### can optionall use -a to output all matching. ### stdin format is: ### [^\t]+:[ \t]+command\n if [ "$1" = "-a" ];then all=1 shift fi uri="$1" ### old way. # line="$(grep "^${scheme}:" ~/.config/uristart.conf | cut -d: -f2- | sed 's/^[ \t]*//g' | sed 's/\\/\\\\/g')" ### going to use urimatchpairs until I get the whole thing rewritten in C grep '^[^#]' \ | while read -r l;do uritmp="$uri" uritmp="$(urimatchpairs $(printf "%s\n" "$l" | cut -d: -f1) \ | while read -r a b;do #printf "pair: '%s' '%s'\n" "$a" "$b" >&2 uritmp="$(printf "%s\n" "${uritmp}" | urimatch $a $b)" printf "%s\n" "${uritmp}" done | tail -n1)" if [ "$uritmp" ];then #printf 'matching line: %s\n' "$l" >&2 printf "%s\n" "$l" if [ ! "$all" ];then break fi fi done \ | cut -d: -f2- \ | sed 's/^[ \t]*//g' \ | sed 's/\\/\\\\/g' ### previous version that doesn't work right for some of the match syntaxes #grep '^[^#]' \ # | while read -r l;do # uritmp="$uri" # uritmp="$(printf "%s\n" "$l" \ # | cut -d: -f1 \ # | tr ' ' '\n' \ # | paste '-d ' - - \ # | while read -r a b;do # uritmp="$(printf "%s\n" "${uritmp}" | urimatch $a $b)" # printf "%s\n" "$uritmp" # done | tail -n1)" # if [ "$uritmp" ];then # printf 'matching line: %s\n' "$l" >&2 # printf '%s\n' "$l" # if [ ! "$all" ]; then # break # fi # fi # done \ # | cut -d: -f2- \ # | sed 's/^[ \t]*//g' \ # | sed 's/\\/\\\\/g'