summaryrefslogtreecommitdiff
path: root/urigetline.sh
diff options
context:
space:
mode:
authorepoch <epoch@enzo.thebackupbox.net>2021-11-14 04:26:25 +0000
committerepoch <epoch@enzo.thebackupbox.net>2021-11-14 04:26:25 +0000
commita0ef1e229f20ea97d5538c8c4a8f1b6045af0c0c (patch)
treed4bf05ad846af0f6a22c49a8ac50cf24a01b96fa /urigetline.sh
parente43385e2cd39e7f31d594b348228d62b41515a68 (diff)
downloaduritools-a0ef1e229f20ea97d5538c8c4a8f1b6045af0c0c.tar.gz
uritools-a0ef1e229f20ea97d5538c8c4a8f1b6045af0c0c.zip
urimatchpairs is new, urigetline got rewritten in C and WEW is it fast now. compare with .sh version.
Diffstat (limited to 'urigetline.sh')
-rwxr-xr-xurigetline.sh60
1 files changed, 60 insertions, 0 deletions
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'