blob: 08eede342bc07c8f20ca7b19d6a7f78033fb170d (
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
|
#!/bin/bash
##might have to configure me.
ASKUSER="dmenu -p"
uri="${1}"
scheme="$(printf "%s\n" "$uri" | uricut -s)"
### experimental crap.. let's comment it out for now.
#if grep '\+' <<< "$scheme" 2>&1 >/dev/null;then
# echo "dunno wtf yet"
# scheme1="$(printf "%s\n" "$scheme" | cut -d+ -f1)+"
# scheme2="+$(printf "%s\n" "$scheme" | cut -d+ -f2)"
# echo $scheme1
# echo $scheme2
# line1="$(grep "^${scheme1}:"$'\t' ~/.config/uristart.conf | tr -s '\t ' | cut -f2- | sed 's/^[ \t]//g' | sed 's/\\n/\\\\n/g')"
# line2="$(grep "^${scheme2}:"$'\t' ~/.config/uristart.conf | tr -s '\t ' | cut -f2- | sed 's/^[ \t]//g' | sed 's/\\n/\\\\n/g')"
# echo $line1
# echo $line2
# pipeline1="$(printf "%s\n" "$uri" | sed 's/'\''/'\''\\'\'''\''/g' | uriprintf "$line1" )"
# pipeline2="$(printf "%s\n" "$uri" | sed 's/'\''/'\''\\'\'''\''/g' | uriprintf "$line2" )"
# echo "$pipeline1"
# echo "$pipeline2"
# mknod /tmp/p p
# cat /tmp/p | bash -xc "$pipeline1" | bash -xc "$pipeline2" > /tmp/p
#else
line="$(grep "^${scheme}:" ~/.config/uristart.conf | cut -d: -f2- | sed 's/^[ \t]//g')"
if printf "%s\n" "$uri" | urimatch nP >/dev/null;then
proto="$(grep ^"$scheme"'[\t ]' /etc/services | tr -s '\t ' | cut -f2 | cut -d/ -f1 | head -n1)"
if [ ! "$proto" ]; then
proto=tcp
fi
uri="$(cat <(printf "%s\n" "$uri" | uricut) \
<(getsrv $(printf "%s\n" "$uri" | uriprintf '%s '"$proto"' %d') 2>&- | tr ':' ' ' | sed 's/ /_port: /' | sed 's/^/domain: /' | tr _ '\n') \
| urijoin)"
printf "srv (%s) modified uri: %s\n" "$proto" "$uri" >&2
fi
if printf "%s\n" "$uri" | urimatch nP >/dev/null;then #if we *still* don't have a port
uri="$(cat <(printf "%s\n" "$uri" | uricut) \
<(grep ^"$scheme"'[\t ]' /etc/services | tr -s '\t ' | cut -f2 | cut -d/ -f1 | head -n1 | sed 's/^/port: /') \
| urijoin)"
printf "getent modified uri: %s\n" "$uri" >&2
fi
echo "the uri we're using: $uri"
if [ "$line" = "" ];then
line="$(printf "" | $ASKUSER "protocol scheme (${scheme}) not configured yet. enter new pipeline to use:")"
if [ "$line" = "" ];then
echo "user noped on entering new pipeline" >&2
exit 1
fi
printf '%s:\t%s\n' "${scheme}" "${line}" >> ~/.config/uristart.conf
fi
## uri *might* contain pattern matching special characters. :/
## which could break things in weird and exciting ways
if ! cut '-d ' -f1 ~/.cache/uristart.log | grep -Fx "$uri" 2>&1 >/dev/null;then #only log URIs that aren't already listed
printf "%s\n" "$uri" >> ~/.cache/uristart.log
fi
eval "$(printf "%s\n" "$uri" | sed 's/'\''/'\''\\'\'''\''/g' | uriprintf "$line")"
#fi
|