Browse Source

Add ffoo includes

Alois Mahdal 10 years ago
parent
commit
113e706f10
4 changed files with 157 additions and 1 deletions
  1. 1
    0
      bin/saturnin-www.skel
  2. 133
    0
      ffoo/www.sh
  3. 11
    0
      ffoo/xorg.sh
  4. 12
    1
      setup/mk.sh

+ 1
- 0
bin/saturnin-www.skel View File

@@ -2,6 +2,7 @@
2 2
 
3 3
 . <(ffoom init)
4 4
 FFOO_INI_PATH="__SATURNIN_INI_PATH__"   # needed for www.find_uri
5
+export FFOO_PATH="__SATURNIN_FFOO_PATH__"      # needed for www and xorg
5 6
 
6 7
 ffoo import ini
7 8
 ffoo import www

+ 133
- 0
ffoo/www.sh View File

@@ -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
+}

+ 11
- 0
ffoo/xorg.sh View File

@@ -0,0 +1,11 @@
1
+#!/bin/bash
2
+
3
+
4
+clipln() {
5
+    #
6
+    # Print primary clipboard and \n
7
+    #
8
+    xclip -o -selection primary 2>/dev/null
9
+    echo ""
10
+}
11
+

+ 12
- 1
setup/mk.sh View File

@@ -8,6 +8,7 @@ sed -e 's/ = /=/' < config.mk > $tmp
8 8
 rm -f $tmp
9 9
 
10 10
 bindir=${DESTDIR}${PREFIX}/bin
11
+shrdir=${DESTDIR}${PREFIX}/share/saturnin/ffoo
11 12
 
12 13
 list_of_bins() {
13 14
     echo bin/saturnin
@@ -34,6 +35,11 @@ die() {
34 35
     exit 9
35 36
 }
36 37
 
38
+list_of_shrs() {
39
+    echo ffoo/www.sh
40
+    echo ffoo/xorg.sh
41
+}
42
+
37 43
 build1() {
38 44
     local srcpath dstpath
39 45
     srcpath=$1
@@ -72,6 +78,7 @@ dist() {
72 78
     mkdir -p $dirname
73 79
     cp -R   bin \
74 80
             config.mk \
81
+            ffoo
75 82
             Makefile \
76 83
             README \
77 84
             LICENSE \
@@ -115,12 +122,15 @@ expand_variables() {
115 122
     #
116 123
     perl -pe "
117 124
         s|__SATURNIN_INI_PATH__|$SATURNIN_INI_PATH_GLOBAL:\\\$HOME/$SATURNIN_INI_PATH_USER|;
125
+        s|__SATURNIN_FFOO_PATH__|$shrdir|;
118 126
         s|__VERSION__|$(get_version)|;
119 127
     "
120 128
 }
121 129
 install() {
122
-    mkdir -vp $bindir
130
+    mkdir -vp $bindir \
131
+              $shrdir
123 132
     list_of_bins | xargs cp -vrt $bindir
133
+    list_of_shrs | xargs cp -vrt $shrdir
124 134
     list_of_installed_bins | xargs chmod -v 755
125 135
     test -f .autoclean && clean || :
126 136
 }
@@ -158,6 +168,7 @@ get_version() {
158 168
 
159 169
 uninstall() {
160 170
     list_of_installed_bins | xargs rm -vf
171
+    rm -vrf $shrdir
161 172
 }
162 173
 
163 174
 case $1 in