summaryrefslogtreecommitdiff
path: root/website.bashcomp
blob: e11cd1581c7a262ce9cecdbd79ae9ffd96ea6a22 (plain)
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
_website_filedir() {
    local IFS=$'\n'
 
    _tilde "$cur" || return 0
 
    local -a toks
    local quoted tmp
 
    _quote_readline_by_ref "$cur" quoted
    toks=( ${toks[@]-} $(
            compgen -d -X "$1" -- "$quoted" | {
                while read -r tmp; do
                    printf '%s/\n' $tmp
                done
            }
            ))
 
    [ ${#toks[@]} -ne 0 ] && compopt -o filenames
 
    COMPREPLY=( "${COMPREPLY[@]}" "${toks[@]}" )
}
 
_website_kinds() {
    local IFS=$'\n'
 
    _tilde "$cur" || return 0
 
    local -a toks
    local quoted tmp
 
    _quote_readline_by_ref "$cur" quoted
    pushd templates >/dev/null
    toks=( ${toks[@]-} $(
            compgen -f -X "!du2html-*.xsl" -- "$quoted" | {
                while read -r tmp; do
                    tmp="${tmp#du2html-}"
                    tmp="${tmp%.xsl}"
                    printf '%s\n' $tmp
                done
            }
            ))
    popd >/dev/null
 
    [ ${#toks[@]} -ne 0 ] &&  compopt -o filenames
 
    COMPREPLY=( "${COMPREPLY[@]}" "${toks[@]}" )
}
 
_website_newdoc() {
    local dir='src'
    local excl='[._]*'
    local cur prev
    _get_comp_words_by_ref cur prev
 
    if [[ $prev == -k ]]; then
        _website_kinds
        return 0
    fi
 
    local offset i
 
    offset=1
    for (( i=1; i <= COMP_CWORD; i++ )); do
        if [[ "${COMP_WORDS[i]}" == -k ]]; then
            i=$(( i + 1 ))
            continue
        fi
        if [[ "${COMP_WORDS[i]}" != -* ]]; then
            offset=$i
            break
        fi
    done
 
    if [[ $(( $COMP_CWORD - $offset )) -gt 0 ]]; then
        dir="${dir}/tags"
    else
        excl="@(${excl}|tags)"
    fi
 
    pushd "$dir" >/dev/null
    _website_filedir "$excl"
    popd >/dev/null
}
 
_website_newtag() {
    false
}
 
complete -o filenames -o nospace -F _website_newdoc ./new-doc
complete -o filenames -o nospace -F _website_newtag ./new-tag