blob: 8589880e8fe76682e54356d959e0daf6fae1bbf4 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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'
|