File: ion-completeman.in

package info (click to toggle)
notion 4.0.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,656 kB
  • sloc: ansic: 47,365; sh: 2,093; makefile: 594; perl: 270
file content (142 lines) | stat: -rwxr-xr-x 2,958 bytes parent folder | download | duplicates (3)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/bin/sh

prog=$0
tocompl=""
section=""
beg=""
action=""
usercache=""
syscache=""
linebeg="^"
icase=""

translate_grepsafe() {
    # The regexp below is supposed to be [\[\].*$^\\], but sed sucks
    # and doesn't support simple and intuitive escaping and we have to
    # do it the hard way with the collations [.[.] and [.].] standing
    # for [ and ], respectively.
    sed 's:^[ \t]*\(.*\)[ \t]*$:\1:; s:[[.[.][.].].*$^\\]:\\&:g'
}


while test $# -ge 1; do
    case "$1" in
        -mid)
            linebeg=""
            ;;
        -icase)
            icase="-i"
            ;;
        -complete)
            read section tocompl << EOF
$2
EOF
            if test "$tocompl" = ""; then
                tocompl="$section"
                section=""
            else
                beg="$section "
            fi
            tocompl=`echo "$tocompl" | translate_grepsafe`
            action="complete"
            break
            ;;
        -mkusercache)
            action="mkusercache"
            break
            ;;
        -mksyscache)
            action="mksyscache"
            break
            ;;
        *)
            break
            ;;
    esac
    shift
done

if test "x$action" = x; then
    echo 2>&1 "Usage: $prog [-icase] [-mid] (-complete what|-mkusercache|-mksyscache)"
    exit 1
fi


filterpath() {
    sed 's:^.*/\([^/]*\.[0-9].*\)$:\1:p; d'
}

filtersect() {
    sed 's:^\(.*\)\.[0-9].*$:\1:p; d'
}

grepper() {
    if test "$tocompl" = "" -a "$section" = ""; then
        cat
    else
        if test "$section" = ""; then
            section="[0-9]"
        fi
        grep $icase "$linebeg$tocompl.*\.$section"
    fi
}

scan() {
    if test "x$ION_MANPATH" != "x"; then
        mpath="$ION_MANPATH"
    elif test "x$MANPATH" != "x"; then
        mpath="$MANPATH"
    else
        mpprog=`which manpath`
        if test "x$mpprog" = x; then
            echo "Please set MANPATH, ION_MANPATH or put 'manpath' on PATH" > /dev/stderr
            exit 1
        fi
        mpath=`$mpprog`
    fi

    for p in `echo "$mpath"|tr : '\n'`; do
        find  "$p" -type f -o -type l | filterpath
    done
}


cachefile=""

if test "x$HOME" != x; then
    usercache="$HOME/.notion/mancache"
fi

syscache="@VARDIR@/mancache"

case "$action" in
    complete)
        if test "x$usercache" != x -a -f "$usercache"; then
            cachefile="$usercache"
        fi

        if test -f "$syscache"; then
            cachefile="$syscache"
        fi

        # Empty "common part" of completions.
        echo "$beg"

        if test "x$cachefile" != x; then
            grepper < "$cachefile" | filtersect
        else
            scan | grepper | filtersect
        fi
        ;;
    mkusercache)
        if test "x$usercache" != x; then
            scan > "$usercache"
        else
            echo >&2 "\$HOME not set."
        fi
        ;;
    mksyscache)
        mkdir -p "@VARDIR@"
        scan > "$syscache"
        ;;
esac