Browse Source

split off bmo: Remove libexec et al

Alois Mahdal 9 years ago
parent
commit
4cb0c465ee

+ 0
- 134
src/ffoo/saturnin_urimagic.sh View File

@@ -1,134 +0,0 @@
1
-#!/bin/bash
2
-
3
-ffoo import inigrep
4
-ffoo import pretty
5
-
6
-
7
-#
8
-# Prefix for inigrep path for 1 and 2-arg queries
9
-#
10
-saturnin_urimagic__inipfx0="${saturnin_urimagic__inipfx0:-}"
11
-saturnin_urimagic__inipfxN="${saturnin_urimagic__inipfxN:-}"
12
-
13
-
14
-saturnin_urimagic__scan() {
15
-    #
16
-    # Scan stdin for what looks like URI, ID or keyword
17
-    #
18
-    # Output URIs: first what were apparent uris, then IDs converted to
19
-    # URIs, then equal sign expressions, then "tags" like bug1234 (i.e.
20
-    # letters+nubmbers, no spaces), then things that looked like
21
-    # kw expressions, converted to URIs.
22
-    #
23
-    # Note that kw expressions (e.g. "bug 123") work only if they start
24
-    # the line.
25
-    #
26
-    # Apply this filter to args or clipboard, and either use head -1 or
27
-    # if you are brave, open all URIs.
28
-    #
29
-    local d=$(mktemp -d -t saturnin_urimagic.XXXXXXXX)
30
-    local p=__saturnin_urimagic__
31
-    pushd "$d" >&/dev/null
32
-        ##
33
-        # heat up and fill pipes
34
-        #
35
-        mkfifo maybe_uris maybe_ids maybe_exps maybe_tags maybe_kws \
36
-               uris uris_from_ids uris_from_exps uris_from_tags uris_from_kws
37
-        cat | tee maybe_uris maybe_ids maybe_exps maybe_tags maybe_kws \
38
-            >/dev/null &
39
-        ##
40
-        # process each pipe *async* by different filter
41
-        #
42
-        < maybe_uris ${p}flt_uris             > uris &
43
-        < maybe_ids  ${p}flt_ids  | ${p}deref > uris_from_ids &
44
-        < maybe_exps ${p}flt_exps | ${p}deref > uris_from_exps &
45
-        < maybe_tags ${p}flt_tags | ${p}deref > uris_from_tags &
46
-        < maybe_kws  ${p}flt_kws  | ${p}deref > uris_from_kws &
47
-        ##
48
-        # print result *sync* in correct order
49
-        #
50
-        {
51
-            cat uris
52
-            cat uris_from_ids
53
-            cat uris_from_exps
54
-            cat uris_from_tags
55
-            cat uris_from_kws
56
-        } | grep .  # throw away empties; add missing LF
57
-    popd >&/dev/null
58
-    rm -rf "$d"
59
-}
60
-
61
-__saturnin_urimagic__deref() {
62
-    #
63
-    # Turn keyword or query (like "g hello" for google) to URI
64
-    #
65
-    local line      # input line,   eg. "g hello dolly" or "bug 1234"
66
-    local kw        # keyword part, eg. "g"             or "bug"
67
-    local query     # query part,   eg. "hello dolly"   or "1234"
68
-    local pfx0=$saturnin_urimagic__inipfx0
69
-    local pfxN=$saturnin_urimagic__inipfxN
70
-    while read kw query;
71
-    do
72
-        debug -v kw query
73
-        if test -n "$query";
74
-        then
75
-            local fmt=$(inigrep -j -1 -p "$pfxN.${kw,,}")
76
-            debug -v fmt
77
-            printf "$fmt\n" "$query"
78
-        else
79
-            inigrep -j -1 -p "$pfx0.$kw"
80
-        fi
81
-    done
82
-}
83
-
84
-__saturnin_urimagic__flt_exps() {
85
-    #
86
-    # Hack expressions like bug = 123 out of the text
87
-    #
88
-    sed -e 's/(\d)\</\n/;' \
89
-      | perl -CS -ne '
90
-            next unless m/\b([a-zA-Z]\w*\s*=\s*\w+)\b/;
91
-            print "$1\n";
92
-        ' \
93
-      | sed -re 's/\s*=\s*/ /' \
94
-      | tr '[:upper:]' '[:lower:]'
95
-}
96
-
97
-__saturnin_urimagic__flt_ids() {
98
-    #
99
-    # Hack doer-like id's (ID#123) out of the text
100
-    #
101
-    tr ' ' '\n' \
102
-      | perl -CS -ne '
103
-            next unless m/\b([a-zA-Z]\w*#\w+)\b/;
104
-            print "$1\n";
105
-        ' \
106
-      | tr '#' ' '
107
-}
108
-
109
-__saturnin_urimagic__flt_kws() {
110
-    #
111
-    # Hack out lines that look like kw expressions
112
-    #
113
-    grep -Ee '^\s*[a-zA-Z]\w*\s+[^=]' -e '^\s*[a-zA-Z]\w*$'
114
-}
115
-
116
-__saturnin_urimagic__flt_tags() {
117
-    #
118
-    # Hack "tags" like bug123 out of the text
119
-    #
120
-    tr ' ' '\n' \
121
-      | grep -E '^[a-zA-Z]+[0-9]+$' \
122
-      | sed -r 's/([a-zA-Z]+)([0-9])/\1 \2/'
123
-}
124
-
125
-__saturnin_urimagic__flt_uris() {
126
-    #
127
-    # Hack URIs out of the text.
128
-    #
129
-    tr ' ' '\n' \
130
-      | perl -CS -ne '
131
-            next unless m|(\bhttps?://[[:alnum:]_:/.?#&+,%@=;~-]+)\b|u;
132
-            print "$1\n";
133
-        '
134
-}

+ 0
- 94
src/ffoo/saturnin_zleep.sh View File

@@ -1,94 +0,0 @@
1
-#!/bin/bash
2
-
3
-ffoo import inigrep
4
-ffoo import pretty
5
-ffoo import sync
6
-
7
-__zleep_user_part() {
8
-    saturnin iam undocking
9
-    slock &
10
-}
11
-
12
-__zleep_try_umount() {
13
-    local mp=$1
14
-    mountpoint -q "$mp" || return 0
15
-    umount        "$mp" || return 1
16
-    mount | grep  "$mp" && return 1
17
-    return 0
18
-}
19
-
20
-__zleep_try_umount_all() {
21
-    local mp
22
-    for mp in $(inigrep -p iam.mounting.point);
23
-    do
24
-        __zleep_try_umount "$mp" || return 1
25
-    done
26
-    return 0
27
-}
28
-
29
-__zleep_sudo_part() {
30
-    wait_until -d 5 -t 30 __zleep_try_umount_all || die "unable to unmount drives"
31
-    pm-suspend
32
-}
33
-
34
-__zleep_sudo_part_started() {
35
-    # i.e. password prompt went ok
36
-    test -e "$ZLEEP_ON_ROOT"
37
-    rv=$?
38
-    debug -v rv
39
-    return $rv
40
-}
41
-
42
-__zleep_user_part_done() {
43
-    ! test -e "$ZLEEP_ON_USER"
44
-    rv=$?
45
-    debug -v rv
46
-    return $rv
47
-}
48
-
49
-__zleep_min_path() {
50
-    echo -n "$(sudo env | grep ^PATH)"
51
-    echo -n :
52
-    echo -n "$(dirname "$(which ffoom)")"
53
-    echo -n :
54
-    echo -n "$(dirname "$(which saturnin)")"
55
-}
56
-
57
-zleep() {
58
-    #
59
-    # Put the host on sleep
60
-    #
61
-    # We need to
62
-    #
63
-    #  1. authenticate
64
-    #  2. start user's part in the background -- mainly slock
65
-    #  3. start root's part -- put system on sleep (unmount, suspend)
66
-    #
67
-    # This is solved by forking with sudo, and waiting for user part to indicate
68
-    # it has finished.  That way, we can ensure that suspend happens *after* the
69
-    # screen has been locked, and at the same time we leave authentication part
70
-    # on sudo.
71
-    #
72
-    if test -z "$ZLEEP_ON_USER";    ## we are parent (running as normal user)
73
-    then
74
-        ZLEEP_ON_USER=$(mktemp)
75
-        ZLEEP_ON_ROOT=$(mktemp -u)
76
-        SUDO_PATH=$(__zleep_min_path)   # needed while bins are still under local
77
-        debug -v ZLEEP_ON_USER ZLEEP_ON_ROOT SUDO_PATH
78
-        sudo env \
79
-            ZLEEP_ON_ROOT="$ZLEEP_ON_ROOT" \
80
-            ZLEEP_ON_USER="$ZLEEP_ON_USER" \
81
-            PATH="$SUDO_PATH" \
82
-            saturnin iam zleeping &
83
-        wait_until -t 60 __zleep_sudo_part_started    # i.e. password prompt done
84
-        __zleep_user_part
85
-        rm -f "$ZLEEP_ON_USER"
86
-    else                            ## we are child (running as root)
87
-        touch "$ZLEEP_ON_ROOT"
88
-        test "$(id -u)" -eq 0               || die "must be root"
89
-        wait_until __zleep_user_part_done   || die "timeout waiting for parent"
90
-        __zleep_sudo_part
91
-        rm -f "$ZLEEP_ON_ROOT"
92
-        return $?
93
-    fi
94
-}

+ 0
- 110
src/libexec/saturnin-au View File

@@ -1,110 +0,0 @@
1
-#!/bin/bash
2
-
3
-. "$(ffoom path)" || exit 3
4
-
5
-ffoo import pretty
6
-
7
-ffoo import saturnin_meta
8
-
9
-
10
-usage() {
11
-    mkusage "up"     \
12
-            "down"   \
13
-            "flip"   \
14
-            "mute"   \
15
-            "query is_muted" \
16
-            "unmute"
17
-}
18
-
19
-
20
-sound_is_muted() {
21
-    #
22
-    # At least one playback channel is muted
23
-    #
24
-    local master_status="$(amixer get Master)"
25
-    echo "$master_status" \
26
-      | grep "Playback channels" \
27
-      | sed -e 's/.*: //; s/ - /\n/' \
28
-      | while read chname
29
-        do
30
-            grep -e "^ *$chname" <<<"$master_status"
31
-        done \
32
-      | grep -qse '\[off\]$'
33
-}
34
-
35
-do_down() {
36
-    #
37
-    # turn volume down
38
-    #
39
-    amixer -q sset Master 5%-
40
-}
41
-
42
-do_flip() {
43
-    #
44
-    # mute or unmute
45
-    #
46
-    if sound_is_muted;
47
-    then
48
-        amixer -q sset Master unmute;
49
-    else
50
-        amixer -q sset Master mute;
51
-    fi
52
-}
53
-
54
-do_mute() {
55
-    #
56
-    # mute
57
-    #
58
-    amixer -q sset Master mute
59
-}
60
-
61
-do_query() {
62
-    #
63
-    # Query properties
64
-    #
65
-    local query="$1"
66
-    debug -v query
67
-    case "$query" in
68
-        is_muted) sound_is_muted; return $? ;;
69
-        *)        usage                     ;;
70
-    esac
71
-}
72
-
73
-do_up() {
74
-    #
75
-    # turn volume up
76
-    #
77
-    amixer -q sset Master 5%+
78
-}
79
-
80
-do_unmute() {
81
-    #
82
-    # mute
83
-    #
84
-    amixer -q sset Master unmute
85
-}
86
-
87
-
88
-action=
89
-while true; do case "$1" in
90
-    up)     action=up;     shift ;;
91
-    down)   action=down;   shift ;;
92
-    flip)   action=flip;   shift ;;
93
-    mute)   action=mute;   shift ;;
94
-    query)  action=query;  shift ; break ;;
95
-    unmute) action=unmute; shift ;;
96
-    "")     break                ;;
97
-    *)      usage                ;;
98
-esac done
99
-
100
-debug "\$*='$*'"
101
-debug -v action
102
-
103
-case $action in
104
-    up|down|flip|mute|query|unmute)
105
-        saturnin_wraphook "do_$action" "$@"
106
-        ;;
107
-    *)
108
-        usage
109
-        ;;
110
-esac

+ 0
- 140
src/libexec/saturnin-clip View File

@@ -1,140 +0,0 @@
1
-#!/bin/bash
2
-
3
-. "$(ffoom path)" || exit 3
4
-
5
-ffoo import inigrep
6
-ffoo import pretty
7
-
8
-
9
-#
10
-# Where to store clips
11
-#
12
-STORAGE_DIR="$SATURNIN_CACHE_HOME/clips"
13
-
14
-usage() {
15
-    mkusage "[ls]" \
16
-            "save [-1|-2|-c]" \
17
-            "load [-1|-2|-c]" \
18
-            "rm" \
19
-            "clean"
20
-}
21
-
22
-clipln() {
23
-    #
24
-    # Print desired clipboard(s) and \n
25
-    #
26
-    case $1 in
27
-        primary|secondary|clipboard)
28
-            xclip -o -selection "$1"   2>/dev/null
29
-            ;;
30
-        ALL)
31
-            xclip -o -selection primary   2>/dev/null
32
-            xclip -o -selection secondary 2>/dev/null
33
-            xclip -o -selection clipboard 2>/dev/null
34
-            ;;
35
-    esac
36
-    echo ""
37
-}
38
-
39
-save_clip() {
40
-    #
41
-    # Save single clip
42
-    #
43
-    local clipname=$1
44
-    mkdir -p "$STORAGE_DIR" || die "could not create directory for saving"
45
-    local path="$STORAGE_DIR/$(date +%Y%m%d-%H%M%S.clip)"
46
-    clipln "$clipname" > "$path"
47
-}
48
-
49
-lsclips() {
50
-    #
51
-    # List clips with MIME types and hints
52
-    #
53
-    local ft hint name
54
-    test -d "$STORAGE_DIR" || return 0
55
-    find "$STORAGE_DIR" -name "*.clip" 2>/dev/null \
56
-      | while read name;
57
-        do
58
-            ft=$(file -b -i "$name" | cut -d\; -f1)
59
-            case $ft in
60
-                text/*)
61
-                    hint=$(head -c 80 "$name" | tr '\n' '↵')
62
-                    ;;
63
-                *)
64
-                    hint=$(head -c 16 "$name" | hexdump -C | head -1)
65
-                    ;;
66
-            esac
67
-            echos "$(basename "$name") || $ft || $hint"
68
-        done
69
-}
70
-
71
-lspaths() {
72
-    #
73
-    # List only clip paths
74
-    #
75
-    ls "$STORAGE_DIR/"*.clip
76
-}
77
-
78
-load_clip() {
79
-    #
80
-    # Load single clip of choice
81
-    #
82
-    local clipname=$1
83
-    local name=$(pick_clip)
84
-    test -n "$name" || return 1
85
-    < "$STORAGE_DIR/$name" xclip -i -selection "$clipname"
86
-}
87
-
88
-rm_clip() {
89
-    #
90
-    # Remove single clip of choice
91
-    #
92
-    local name=$(pick_clip)
93
-    test -n "$name" || return 1
94
-    rm -f "$STORAGE_DIR/$name"
95
-}
96
-
97
-rm_all() {
98
-    #
99
-    # Drop all clips
100
-    #
101
-    test -n "$STORAGE_DIR" || die "storage directory is unset, aborting"
102
-    test -d "$STORAGE_DIR" || return 0
103
-    find "$STORAGE_DIR" -name "*.clip" -print0 | xargs -0 rm -f
104
-    rmdir "$STORAGE_DIR" 2>/dev/null | :
105
-}
106
-
107
-pick_clip() {
108
-    saturnin clip ls \
109
-      | saturnin dmenu \
110
-      | cut -d\   -f 1
111
-}
112
-
113
-
114
-clipname=primary
115
-action=list_nice
116
-while true; do case "$1" in
117
-    save)   action=save;        shift ;;
118
-    load)   action=load;        shift ;;
119
-    ls)     action=list;        shift ;;
120
-    lsh)    action=list_nice    shift ;;
121
-    rm)     action=remove;      shift ;;
122
-    clean)  action=clean;       shift ;;
123
-    -1)     clipname=primary;   shift ;;
124
-    -2)     clipname=secondary; shift ;;
125
-    -c)     clipname=clipboard; shift ;;
126
-    "")     break                     ;;
127
-    *)      usage                     ;;
128
-esac done
129
-
130
-debug "\$*='$*'"
131
-debug -v clipname action
132
-
133
-case $action in
134
-    save)       save_clip $clipname ;;
135
-    load)       load_clip $clipname ;;
136
-    remove)     rm_clip ;;
137
-    clean)      rm_all ;;
138
-    list)       lspaths ;;
139
-    list_nice)  lsclips ;;
140
-esac

+ 0
- 46
src/libexec/saturnin-dmenu View File

@@ -1,46 +0,0 @@
1
-#!/bin/bash
2
-
3
-. "$(ffoom path)" || exit 3
4
-
5
-ffoo import inigrep
6
-ffoo import pretty
7
-
8
-usage() {
9
-    mkusage "[-l|--lines NUM] [--split CHAR] ARGS..."
10
-}
11
-
12
-lines=10
13
-maybe_split=cat
14
-delim=" "
15
-field=2-
16
-
17
-while true; do case $1 in
18
-    -l|--lines)     lines=$2; shift 2 || usage ;;
19
-    --split)        delim=$2; maybe_split=do_split; shift 2 || usage ;;
20
-    --split-field)  field=$2; maybe_split=do_split; shift 2 || usage ;;
21
-    --help|--usage) usage             ;;
22
-    *)              break             ;;
23
-esac done
24
-
25
-nb="$(inigrep -1 -p style.color.nbg)"
26
-nf="$(inigrep -1 -p style.color.nfg)"
27
-sb="$(inigrep -1 -p style.color.sbg)"
28
-sf="$(inigrep -1 -p style.color.sfg)"
29
-fn="$(inigrep -1 -p style.font)"
30
-fn=${fn:--*-terminus-medium-r-*-*-16-*-*-*-*-*-*-*}
31
-
32
-debug -v nb nf sb sf fn lines maybe_split delim
33
-
34
-style() {
35
-    test -n "$nb" && echo -n "-nb $nb "
36
-    test -n "$nf" && echo -n "-nf $nf "
37
-    test -n "$sb" && echo -n "-sb $sb "
38
-    test -n "$sf" && echo -n "-sf $sf "
39
-    test -n "$fn" && echo -n "-fn $fn "
40
-}
41
-
42
-do_split() {
43
-    cut "-d$delim" -f"$field"
44
-}
45
-
46
-dmenu -b -i -l "$lines" $(style) "$@" | $maybe_split

+ 0
- 126
src/libexec/saturnin-iam View File

@@ -1,126 +0,0 @@
1
-#!/bin/bash
2
-
3
-. "$(ffoom path)" || exit 3
4
-
5
-ffoo import inigrep
6
-ffoo import pretty
7
-ffoo import sync
8
-
9
-ffoo import saturnin_meta
10
-ffoo import saturnin_zleep
11
-
12
-
13
-#
14
-# self help
15
-#
16
-
17
-available_commands="afk at back gone ooo wfh undocking zleeping"
18
-
19
-usage() {
20
-    mkusage "$available_commands"
21
-}
22
-
23
-
24
-#
25
-# querying
26
-#
27
-
28
-where_i_am() {
29
-    #
30
-    # what is my physical location?
31
-    #
32
-    if=$(inigrep -p iam.using.if)
33
-    gwmac=$(arp | grep "^gateway\\>.*\\<$if\$" | tr ' ' '\n' | grep :)
34
-    inigrep -p "iam.seeing.gw.$gwmac" || echo OUT
35
-}
36
-
37
-set_status() {
38
-    #
39
-    # set public status $1 by command in conf file
40
-    #
41
-    local what=$1
42
-    saturnin_runhook "say_$what"
43
-    saturnin_runhook "log_$what"
44
-}
45
-
46
-
47
-#
48
-# subcommand handlers
49
-#
50
-
51
-i_am_afk() {
52
-    #
53
-    # away from keyboard; blocks until i'm back again
54
-    #
55
-    saturnin_runhook "afk"
56
-    set_status "afk"
57
-    saturnin kb home    # make sure to set lang to default before locking
58
-    slock
59
-    set_status "atk"
60
-}
61
-
62
-i_am_at() {
63
-    #
64
-    # Just say where I am
65
-    #
66
-    where_i_am
67
-}
68
-
69
-i_am_back() {
70
-    #
71
-    # returning to work (should be called by other subcommands)
72
-    #
73
-    set_status "back"
74
-    klist -s || urxvt -e kinit
75
-}
76
-
77
-i_am_gone() {
78
-    #
79
-    # gone fishin'
80
-    #
81
-    kdestroy
82
-    ssh-add -D
83
-    set_status "gone"
84
-    i_am_afk
85
-    i_am_back
86
-}
87
-
88
-i_am_ooo() {
89
-    #
90
-    # too dangerous to implement
91
-    #
92
-    die "not implemented"
93
-}
94
-
95
-i_am_wfh() {
96
-    #
97
-    # too dangerous to implement
98
-    #
99
-    die "not implemented"
100
-}
101
-
102
-i_am_undocking() {
103
-    #
104
-    # i.e. hibernated
105
-    #
106
-    inigrep -p iam.undocking.like | bash -
107
-}
108
-
109
-i_am_zleeping() {
110
-    #
111
-    # i.e. hibernated
112
-    #
113
-    set_status "zleeping"
114
-    zleep
115
-    i_am_back
116
-}
117
-
118
-cmd=$1
119
-
120
-test -n "$cmd" || usage
121
-
122
-echo "$available_commands" | grep -qw "$cmd" || usage
123
-
124
-shift
125
-
126
-"i_am_$cmd" "$1"

+ 0
- 59
src/libexec/saturnin-kb View File

@@ -1,59 +0,0 @@
1
-#!/bin/bash
2
-
3
-. "$(ffoom path)" || exit 3
4
-
5
-ffoo import inigrep
6
-ffoo import pretty
7
-
8
-
9
-usage() {
10
-    mkusage "[show]" \
11
-            "next" \
12
-            "home" \
13
-            "layout LAYOUT"
14
-}
15
-
16
-next_layout() {
17
-    #
18
-    # change layout to the next one in row
19
-    #
20
-    local cur="$current_layout"
21
-    local all="$(inigrep -p kb.layout)"
22
-    local def="$default_layout"
23
-    local nxt=$(
24
-        echo -e "$all\n$all" \
25
-          | grep -m 1 -A 1 "$cur" \
26
-          | tail -1
27
-    )
28
-    test -z "$nxt" && nxt=$def
29
-    test -z "$nxt" && nxt=us
30
-    debug -v all def cur nxt
31
-    echo "$nxt"
32
-}
33
-
34
-default_layout="$(inigrep -1 -p kb.layout)"
35
-current_layout="$(setxkbmap -v | grep '^symbols: ' | cut -d+ -f2)"
36
-
37
-layout=""
38
-action=show
39
-case "$1" in
40
-    home)     action=set; layout="$default_layout" ;;
41
-    next)     action=set; layout="$(next_layout)"  ;;
42
-    layout)   action=set; layout="$2"              ;;
43
-    ""|show)  true                                 ;;
44
-    *)        usage                                ;;
45
-esac
46
-
47
-
48
-debug -v layout current_layout default_layout
49
-
50
-case "$action" in
51
-    show)
52
-        echo "$current_layout"
53
-        exit
54
-        ;;
55
-    set)
56
-        test -n "$layout" || usage
57
-        setxkbmap "$layout"
58
-        ;;
59
-esac

+ 0
- 48
src/libexec/saturnin-ln View File

@@ -1,48 +0,0 @@
1
-#!/bin/bash
2
-
3
-. "$(ffoom path)" || exit 3
4
-
5
-ffoo import inigrep
6
-ffoo import pretty
7
-
8
-DEFAULT_TARGET=$HOME
9
-
10
-usage() {
11
-    mkusage "[-t|--target TARGET] [SOURCE] [NAME]"
12
-}
13
-
14
-expand_tilde() {
15
-    #
16
-    # Exchange "~" for home
17
-    #
18
-    perl -pe "s|^[[:space:]]*~|$HOME|"
19
-}
20
-
21
-link() {
22
-    local src=$1
23
-    local dst=$2
24
-    think "linking $src to $dst"
25
-    rm -f "$dst"
26
-    ln -sr "$src" "$dst"
27
-}
28
-
29
-load() {
30
-    inigrep -p "ln.dir.$1" | expand_tilde
31
-}
32
-
33
-while true; do case $1 in
34
-    -t|--target)        target=$2           shift 2 || usage ;;
35
-    --help)             usage                       ;;
36
-    -*)                 usage                       ;;
37
-    *)                  src=$1; name=$2;    break   ;;
38
-esac done
39
-
40
-test -z "$target"               && target=$(load target)
41
-test -z "$target"               && target=$DEFAULT_TARGET
42
-test -z "$name"                 && name="$(basename "$PWD")"
43
-test -z "$src"                  && src="."
44
-
45
-debug -v src name target
46
-
47
-mkdir -p "$target"
48
-link "$src" "$target/$name"

+ 0
- 156
src/libexec/saturnin-menu View File

@@ -1,156 +0,0 @@
1
-#!/bin/bash
2
-
3
-. "$(ffoom path)" || exit 3
4
-
5
-ffoo import inigrep
6
-ffoo import pretty
7
-
8
-usage() {
9
-    mkusage "[-g generator_cmd] [-s selector_cmd] [-c consumer_cmd] [name]"
10
-}
11
-
12
-SATURNIN_MENU_MNAME=""
13
-SATURNIN_MENU_GENERATOR=""
14
-SATURNIN_MENU_SELECTOR=""
15
-SATURNIN_MENU_SELECT_ARGS=""
16
-SATURNIN_MENU_CONSUMER=""
17
-
18
-load_parts() {
19
-    #
20
-    # Load mandatory parts for menu name $1
21
-    #
22
-    local mname
23
-
24
-    # last chance to get mname
25
-    test -n "$SATURNIN_MENU_MNAME" \
26
-     || SATURNIN_MENU_MNAME="$(get_mname)" \
27
-     || usage
28
-    mname="$SATURNIN_MENU_MNAME"
29
-
30
-    # check that menu item exists
31
-    inigrep -s "menu.$mname" | grep -q . \
32
-     || die "no such menu: $mname"
33
-
34
-    test -n "$SATURNIN_MENU_GENERATOR" \
35
-     || SATURNIN_MENU_GENERATOR="$(get_generator)"  \
36
-     || die "cannot find generator for menu: $mname"
37
-
38
-    test -n "$SATURNIN_MENU_SELECTOR" \
39
-     || SATURNIN_MENU_SELECTOR="$(get_selector)" \
40
-     || die "cannot find selector for menu: $mname"
41
-
42
-    test -n "$SATURNIN_MENU_SELECT_ARGS" \
43
-     || SATURNIN_MENU_SELECT_ARGS="$(get_select_args)"
44
-
45
-    test -n "$SATURNIN_MENU_CONSUMER" \
46
-     || SATURNIN_MENU_CONSUMER="$(get_consumer)" \
47
-     || die "cannot find consumer for menu: $mname"
48
-}
49
-
50
-get_mname() {
51
-    #
52
-    # Take from global INI default
53
-    #
54
-    inigrep -1 -p menu._default_.name | grep .
55
-}
56
-
57
-get_generator() {
58
-    #
59
-    # Obtain and echo generator for menu $mname
60
-    #
61
-    # First, look for 'generator' key in menu definition,
62
-    # then for items as 'item' keys at the same place,
63
-    # finally default 'generator'.
64
-    #
65
-    inigrep -1 -p "menu.$mname.generator" | grep . \
66
-     && return 0
67
-    inigrep -p "menu.$mname.item" | grep -m 1 -q . \
68
-     && echo "inigrep -p menu.$mname.item" \
69
-     && return 0
70
-    inigrep -1 -p "menu._default_.generator" | grep . \
71
-     && return 0
72
-    return 1
73
-}
74
-
75
-get_selector() {
76
-    #
77
-    # Obtain and echo selector for menu $mname
78
-    #
79
-    # First, look for 'selector' key in menu definition,
80
-    # then a default 'selector'.
81
-    #
82
-    inigrep -1 -p "menu.$mname.selector" | grep . \
83
-     && return 0
84
-    inigrep -1 -p "menu._default_.selector" | grep .
85
-}
86
-
87
-get_select_args() {
88
-    #
89
-    # Obtain and echo selector args for menu $mname
90
-    #
91
-    # First, look for 'select_args' key in menu definition,
92
-    # then a default 'select_args'.
93
-    #
94
-    inigrep -1 -p "menu.$mname.select_args" | grep . \
95
-     && return 0
96
-    inigrep -1 -p "menu._default_.select_args"
97
-}
98
-
99
-get_consumer() {
100
-    #
101
-    # Obtain and echo consumer args for menu $mname
102
-    #
103
-    # First, look for 'consumer' key in menu definition,
104
-    # then a default 'consumer'.
105
-    #
106
-    inigrep -1 -p "menu.$mname.consumer" | grep . \
107
-     && return 0
108
-    inigrep -1 -p "menu._default_.consumer" | grep .
109
-}
110
-
111
-do_generate() {
112
-    #
113
-    # Generate menu items
114
-    #
115
-    bash -n <<<"$SATURNIN_MENU_GENERATOR" \
116
-     || die "syntax errors in generator: $SATURNIN_MENU_GENERATOR"
117
-    eval "$SATURNIN_MENU_GENERATOR"
118
-}
119
-
120
-do_select() {
121
-    #
122
-    # Bring up selection UI
123
-    #
124
-    bash -n <<<"$SATURNIN_MENU_SELECTOR" \
125
-     || die "syntax errors in selector: $SATURNIN_MENU_SELECTOR"
126
-    eval "$SATURNIN_MENU_SELECTOR $SATURNIN_MENU_SELECT_ARGS"
127
-}
128
-
129
-
130
-do_consume() {
131
-    #
132
-    # Process the selected item(s)
133
-    #
134
-    bash -n <<<"$SATURNIN_MENU_CONSUMER" \
135
-     || die "syntax errors in consumer: $SATURNIN_MENU_CONSUMER"
136
-    eval "$SATURNIN_MENU_CONSUMER"
137
-}
138
-
139
-while true; do case "$1" in
140
-    -g) SATURNIN_MENU_GENERATOR="$2"; shift; shift ;;
141
-    -s) SATURNIN_MENU_SELECTOR="$2"; shift; shift ;;
142
-    -c) SATURNIN_MENU_CONSUMER="$2"; shift; shift ;;
143
-    -*) usage ;;
144
-    "") usage ;;
145
-    *)  SATURNIN_MENU_MNAME="$1"; shift; break ;;
146
-esac done
147
-
148
-load_parts
149
-
150
-debug -v SATURNIN_MENU_MNAME \
151
-         SATURNIN_MENU_GENERATOR \
152
-         SATURNIN_MENU_SELECTOR \
153
-         SATURNIN_MENU_SELECT_ARGS \
154
-         SATURNIN_MENU_CONSUMER
155
-
156
-do_generate | do_select | do_consume

+ 0
- 72
src/libexec/saturnin-uris View File

@@ -1,72 +0,0 @@
1
-#!/bin/bash
2
-
3
-. "$(ffoom path)" || exit 3
4
-
5
-ffoo import inigrep
6
-ffoo import pretty
7
-
8
-ffoo import saturnin_urimagic
9
-
10
-saturnin_urimagic__inipfx0="uris.bookmark"
11
-saturnin_urimagic__inipfxN="uris.query"
12
-
13
-#
14
-# On clipboards:
15
-#
16
-#   *  primary is for selection/middle mouse click (X power users)
17
-#   *  clipboard is for Win/Mac-like explicit Copy/Cut/Paste
18
-#   *  nobody uses secondary
19
-#
20
-# see http://standards.freedesktop.org/clipboards-spec/clipboards-latest.txt
21
-# for more details
22
-#
23
-
24
-usage() {
25
-    mkusage "word..."      \
26
-            "-f file"      \
27
-            "-1|-2|-c|-C"
28
-}
29
-
30
-clipln() {
31
-    #
32
-    # Print primary clipboard and \n
33
-    #
34
-    case $1 in
35
-        pri) s=primary   ;;
36
-        sec) s=secondary ;;
37
-        clp) s=clipboard ;;
38
-    esac
39
-    xclip -o -selection $s 2>/dev/null
40
-    echo ""
41
-}
42
-
43
-src=args
44
-while true; do case "$1" in
45
-    -f) src=file; file=$2; shift 2 || usage ;;
46
-    -1) src=xpri;          shift   ;;
47
-    -2) src=xsec;          shift   ;;
48
-    -c) src=xclp;          shift   ;;
49
-    -C) src=xall;          shift   ;;
50
-    -*) usage                      ;;
51
-    *)  break ;;
52
-esac done
53
-
54
-debug "\$*='$*'"
55
-debug -v src
56
-
57
-case "$src" in
58
-    args) uri="$(echo "$@" | saturnin_urimagic__scan)" ;;
59
-    file) uri="$(cat "$file" | saturnin_urimagic__scan)" ;;
60
-    xpri) uri="$(clipln pri | saturnin_urimagic__scan)" ;;
61
-    xsec) uri="$(clipln sec | saturnin_urimagic__scan)" ;;
62
-    xclp) uri="$(clipln clp | saturnin_urimagic__scan)" ;;
63
-    xall) uri="$(clipln pri | saturnin_urimagic__scan)"
64
-          uri="$(clipln sec | saturnin_urimagic__scan)"
65
-          uri="$(clipln clp | saturnin_urimagic__scan)"
66
-          ;;
67
-esac
68
-debug -v uri
69
-
70
-test -z "$uri" && uri="$(inigrep -p uris.bookmark.default)"
71
-
72
-echo "$uri"

+ 0
- 80
src/libexec/saturnin-xuris View File

@@ -1,80 +0,0 @@
1
-#!/bin/bash
2
-
3
-# launch Uzbl once per each URI in stdin
4
-
5
-. "$(ffoom path)" || exit 3
6
-ffoo import pretty
7
-ffoo import inigrep
8
-
9
-SATURNIN_XURIS_NOTIFICATIONS=true
10
-SATURNIN_XURIS_LIMIT=100
11
-SATURNIN_XURIS_ALWAYS_RUN=false
12
-SATURNIN_XURIS_UNIQ=true
13
-SATURNIN_XURIS_CHOICE="${SATURNIN_XURIS_CHOICE:-false}"
14
-
15
-usage() {
16
-    mkusage "[-u|--uniq] [-a|--always-run] [-l|--limit N] [-c|--choose] [-C|--choice-cmd COMMAND]"
17
-}
18
-
19
-maybe_uniq() {
20
-    $SATURNIN_XURIS_UNIQ || { cat; return; }
21
-    sort | uniq
22
-}
23
-
24
-notify() {
25
-    $SATURNIN_XURIS_NOTIFICATIONS || return 0
26
-    local summary="saturnin-xuris"
27
-    local body="$1"
28
-    notify-send -a saturnin-xuris "$summary" "$body"
29
-}
30
-
31
-open_from() {
32
-    local list="$1"
33
-    local count=$(wc -l <"$list")
34
-
35
-    test "$count" -gt $SATURNIN_XURIS_LIMIT && {
36
-        notify "too much URIs; giving up: $count > $SATURNIN_XURIS_LIMIT"
37
-        return 1
38
-    }
39
-
40
-    test "$count" -eq 0 && {
41
-        $SATURNIN_XURIS_ALWAYS_RUN && $SATURNIN_XURIS_BIN &
42
-        return 0
43
-    }
44
-
45
-    while read uri;
46
-    do
47
-        $SATURNIN_XURIS_BIN "$uri" &
48
-    done < "$list"
49
-}
50
-
51
-while true; do case $1 in
52
-    -a|--always-run) SATURNIN_XURIS_ALWAYS_RUN=true; shift ;;
53
-    -b|--bin)        SATURNIN_XURIS_BIN="$2"; shift; shift ;;
54
-    -c|--choose)     SATURNIN_XURIS_CHOICE="inigrep -j -p xuris.browsers | saturnin dmenu"; shift ;;
55
-    -C|--choice-cmd) SATURNIN_XURIS_CHOICE="$2"; shift; shift ;;
56
-    -l|--limit)      SATURNIN_XURIS_LIMIT=$2; shift; shift ;;
57
-    -u|--uniq)       SATURNIN_XURIS_UNIQ=true;       shift ;;
58
-    -U|--no-uniq)    SATURNIN_XURIS_UNIQ=false;      shift ;;
59
-    -*)       usage ;;
60
-    "")       break ;;
61
-    *)        usage ;;
62
-esac done
63
-
64
-debug -v SATURNIN_XURIS_ALWAYS_RUN \
65
-         SATURNIN_XURIS_CHOICE \
66
-         SATURNIN_XURIS_LIMIT \
67
-         SATURNIN_XURIS_UNIQ
68
-
69
-SATURNIN_XURIS_URI_LIST=$(mktemp -t saturnin-xuris.XXXXXXXX)
70
-cat | maybe_uniq | grep . >"$SATURNIN_XURIS_URI_LIST"
71
-
72
-# choice of URI has been made; we may try to use dmenu
73
-bash -n <<<"$SATURNIN_XURIS_CHOICE"
74
-SATURNIN_XURIS_BIN=$(eval "$SATURNIN_XURIS_CHOICE")
75
-SATURNIN_XURIS_BIN="${SATURNIN_XURIS_BIN:-$(inigrep -j -1 -p xuris.default_browser)}"
76
-
77
-debug -v SATURNIN_XURIS_BIN
78
-
79
-open_from "$SATURNIN_XURIS_URI_LIST"
80
-rm "$SATURNIN_XURIS_URI_LIST"