From a0ef1e229f20ea97d5538c8c4a8f1b6045af0c0c Mon Sep 17 00:00:00 2001 From: epoch Date: Sun, 14 Nov 2021 04:26:25 +0000 Subject: urimatchpairs is new, urigetline got rewritten in C and WEW is it fast now. compare with .sh version. --- urigetline.sh | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100755 urigetline.sh (limited to 'urigetline.sh') diff --git a/urigetline.sh b/urigetline.sh new file mode 100755 index 0000000..8589880 --- /dev/null +++ b/urigetline.sh @@ -0,0 +1,60 @@ +#!/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' -- cgit v1.2.3