aboutsummaryrefslogtreecommitdiffstats
path: root/urigetline
blob: 3f6bb51bfc274d2aeadd0fae8a0e96fe9359ad9d (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
#!/bin/bash
uri="$1"
### old way.
# line="$(grep "^${scheme}:" ~/.config/uristart.conf | cut -d: -f2- | sed 's/^[ \t]*//g' | sed 's/\\/\\\\/g')"

if [ ! "$uristart_config" ];then
  uristart_config=~/.config/uristart.conf
fi

### fancy way.
grep '^[^#]' "$uristart_config" \
  | 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 '%s\n' "$l"
                break
        fi
    done \
  | cut -d: -f2- \
  | sed 's/^[ \t]*//g' \
  | sed 's/\\/\\\\/g'