|
@@ -0,0 +1,133 @@
|
|
1
|
+#!/bin/bash
|
|
2
|
+
|
|
3
|
+ffoo import core
|
|
4
|
+ffoo import ini
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+filter_exprs() {
|
|
8
|
+ #
|
|
9
|
+ # Hack expressions like bug = 123 out of the text
|
|
10
|
+ #
|
|
11
|
+ sed -e 's/(\d)\</\n/;'\
|
|
12
|
+ | perl -ne '
|
|
13
|
+ next unless m/\b([a-zA-Z]{2,}\s*=\s*\d+)\b/;
|
|
14
|
+ print "$1\n";
|
|
15
|
+ ' \
|
|
16
|
+ | debug_pipe id_lookalikes
|
|
17
|
+}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+filter_ids() {
|
|
21
|
+ #
|
|
22
|
+ # Hack doer-like id's (ID#123) out of the text
|
|
23
|
+ #
|
|
24
|
+ tr ' ' '\n' \
|
|
25
|
+ | perl -ne '
|
|
26
|
+ next unless m/\b([a-zA-Z]{2,}#\d+)\b/;
|
|
27
|
+ print "$1\n";
|
|
28
|
+ ' \
|
|
29
|
+ | debug_pipe id_lookalikes
|
|
30
|
+}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+filter_kws() {
|
|
34
|
+ #
|
|
35
|
+ # Hack out lines that look like kw expressions
|
|
36
|
+ #
|
|
37
|
+ local kwbase="[a-z][a-z0-9]*"
|
|
38
|
+ grep -e "^$kwbase " -e "^$kwbase\$" \
|
|
39
|
+ | debug_pipe kw_lookalikes
|
|
40
|
+}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+filter_uris() {
|
|
44
|
+ #
|
|
45
|
+ # Hack URIs out of the text.
|
|
46
|
+ #
|
|
47
|
+ tr ' ' '\n' \
|
|
48
|
+ | perl -ne '
|
|
49
|
+ next unless m|(\bhttps?://[[:alnum:]_:/.?&+%@=-]+)\b|;
|
|
50
|
+ print "$1\n";
|
|
51
|
+ ' \
|
|
52
|
+ | debug_pipe uri_lookalikes
|
|
53
|
+}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+find_uri() {
|
|
57
|
+ #
|
|
58
|
+ # Scan stdin for what looks like URI, ID or keyword
|
|
59
|
+ #
|
|
60
|
+ # Output URIS: first what were apparent uris, then IDs converted to
|
|
61
|
+ # URIs, then equal sign expressions, then things that looked like
|
|
62
|
+ # kw expressions, converted to URIs.
|
|
63
|
+ #
|
|
64
|
+ # Apply this filter to args or clipboard, and either use head -1 or
|
|
65
|
+ # if you are brave, open all URIs.
|
|
66
|
+ #
|
|
67
|
+ local d=$(mktemp -d)
|
|
68
|
+ pushd $d >&/dev/null
|
|
69
|
+ ##
|
|
70
|
+ # heat up and fill pipes
|
|
71
|
+ #
|
|
72
|
+ mkfifo maybe_uris maybe_ids maybe_exprs maybe_kws \
|
|
73
|
+ uris uris_from_ids uris_from_exprs uris_from_kws
|
|
74
|
+ cat | tee maybe_uris maybe_ids maybe_exprs maybe_kws >/dev/null &
|
|
75
|
+ ##
|
|
76
|
+ # process each pipe *async* by different filter
|
|
77
|
+ #
|
|
78
|
+ cat maybe_uris | filter_uris > uris &
|
|
79
|
+ cat maybe_ids | filter_ids | id2kw | kw2uri > uris_from_ids &
|
|
80
|
+ cat maybe_exprs | filter_exprs | expr2kw | kw2uri > uris_from_exprs &
|
|
81
|
+ cat maybe_kws | filter_kws | kw2uri > uris_from_kws &
|
|
82
|
+ ##
|
|
83
|
+ # print result *sync* in correct order
|
|
84
|
+ #
|
|
85
|
+ {
|
|
86
|
+ cat uris
|
|
87
|
+ cat uris_from_ids
|
|
88
|
+ cat uris_from_exprs
|
|
89
|
+ cat uris_from_kws
|
|
90
|
+ } | grep . # throw away empties; add missing LF
|
|
91
|
+ popd >&/dev/null
|
|
92
|
+ rm -rf $d
|
|
93
|
+}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+id2kw() {
|
|
97
|
+ #
|
|
98
|
+ # Convert doer-like ID to kw expression
|
|
99
|
+ #
|
|
100
|
+ tr '#' ' '
|
|
101
|
+}
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+expr2kw() {
|
|
105
|
+ #
|
|
106
|
+ # Convert equal sign expression to kw expression
|
|
107
|
+ #
|
|
108
|
+ sed -re 's/\s*=\s*/ /' | tr '[:upper:]' '[:lower:]'
|
|
109
|
+}
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+kw2uri() {
|
|
113
|
+ #
|
|
114
|
+ # Turn keyword or query (like "g hello" for google) to URI
|
|
115
|
+ #
|
|
116
|
+ local line
|
|
117
|
+ declare -l line
|
|
118
|
+ while read line;
|
|
119
|
+ do
|
|
120
|
+ line="$line "
|
|
121
|
+ local kw=${line%% *}
|
|
122
|
+ local query=${line#$kw }
|
|
123
|
+ debug -v kw query
|
|
124
|
+ if test -n "$query";
|
|
125
|
+ then
|
|
126
|
+ local fmt=$(iniread -1 -p www.query.$kw)
|
|
127
|
+ debug -v fmt
|
|
128
|
+ printf "$fmt\n" "$query"
|
|
129
|
+ else
|
|
130
|
+ iniread -1 -p www.bookmark.$kw
|
|
131
|
+ fi
|
|
132
|
+ done
|
|
133
|
+}
|