aboutsummaryrefslogtreecommitdiffstats
path: root/urigetline.sh
diff options
context:
space:
mode:
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'