aboutsummaryrefslogtreecommitdiff
path: root/bash-completion/paludis
blob: d6e33e5927b74121a7b3615b2f52e660360b43f5 (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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
# Bash completion function for paludis
# Written by Mike Kelly
# vim: set et sw=4 sts=4 ts=4 ft=sh :

# NOTE: This is still a work in progress, don't expect it to work well or
# properly right now.

_paludis_packagenames() {
    for names_cache in $(paludis --list-repositories --log-level silent |sed -n 's,^[[:space:]]*names_cache:[[:space:]]*\(.*\)$,\1,p')
    do
        pushd "${names_cache}" 1>/dev/null
        for d in * ; do
            [[ -d "${d}" ]] || continue
            pushd "${d}" 1>/dev/null
            for x in "${1}"* ; do
                [[ -f "${x}" ]] && echo $x
            done
            popd 1>/dev/null
        done
        popd 1>/dev/null
    done
}

_paludis_dolist() {
    paludis --list-${1} --log-level silent |sed -n 's,^\* \(.*\),\1,p'
}

_paludis() {
    local cur prev opts action

    local action_opts general_opts deplist_opts
    local query_opts install_opts uninstall_opts sync_opts report_opts
    local contents_opts owner_opts info_opts version_query_opts
    local env_variable_query_opts conf_variable_query_opts
    local list_opts regen_opts all_opts

    COMPREPLY=()
    cur=${COMP_WORDS[COMP_CWORD]}
    prev=${COMP_WORDS[COMP_CWORD-1]}

    action_opts="--query -q \
        --install -i \
        --uninstall -u \
        --uninstall-unused \
        --sync -s \
        --report -r \
        --contents -k \
        --owner -o \
        --config \
        --version -V \
        --info -I \
        --help -h \
        --has-version \
        --best-version \
        --match \
        --environment-variable \
        --configuration-variable \
        --list-repositories \
        --list-categories \
        --list-packages \
        --list-sets \
        --list-sync-protocols \
        --list-repository-formats \
        --list-dep-tag-categories \
        --regenerate-installed-cache \
        --regenerate-installable-cache"
    general_opts="--log-level \
        --no-colour \
        --no-color \
        --no-suggestions \
        --environment -E \
        --resume-command-template \
        --multitask"

    deplist_opts="--dl-reinstall \
        --dl-reinstall-scm \
        --dl-reinstall-targets \
        --dl-upgrade \
        --dl-new-slots \
        --dl-downgrade \
        --dl-deps-default \
        --dl-installed-deps-pre \
        --dl-installed-deps-runtime \
        --dl-installed-deps-post \
        --dl-uninstalled-deps-pre \
        --dl-uninstalled-deps-runtime \
        --dl-uninstalled-deps-post \
        --dl-uninstalled-deps-suggested \
        --dl-suggested \
        --dl-circular \
        --dl-blocks \
        --dl-override-masks \
        --dl-fall-back"

    query_opts="--show-deps -D \
        --show-metadata -M \
        --compact"
    install_opts="--pretend -p \
        --destinations -d \
        --preserve-world -1 \
        --add-to-world-spec \
        --no-config-protection \
        --debug-build \
        --checks \
        --fetch -f \
        --no-safe-resume \
        --show-reasons \
        --show-use-descriptions \
        --show-package-descriptions \
        --continue-on-failure \
        --compact \
        ${deplist_opts}"
    uninstall_opts="--pretend -p \
        --destinations -d \
        --preserve-world -1 \
        --no-config-protection \
        --show-reasons \
        --show-use-descriptions \
        --show-package-descriptions \
        --with-unused-dependencies \
        --permit-unsafe-uninstalls \
        --with-dependencies \
        --all-versions \
        ${deplist_opts}"
    sync_opts=""
    report_opts=""
    contents_opts=""
    owner_opts="--full-match"
    info_opts=""
    version_query_opts=""
    env_variable_query_opts=""
    conf_variable_query_opts=""
    list_opts="--repository \
        --repository-format \
        --category \
        --package \
        --set"
    regen_repos_opts=""
        
    all_opts="${action_opts} ${general_opts} ${query_opts} ${install_opts} ${uninstall_opts} ${sync_opts} ${report_opts} ${contents_opts} ${owner_opts} ${version_query_opts} ${variable_query_opts} ${list_opts} ${regen_repos_opts}"

    local x
    for x in "${COMP_WORDS[@]}" ; do
        case "${x}" in
            -q|--query)
                action="query"
                break
                ;;
            -i|--install)
                action="install"
                break
                ;;
            -u|--uninstall|--uninstall-unused)
                action="uninstall"
                break
                ;;
            -s|--sync)
                action="sync"
                break
                ;;
            -r|--report)
                action="report"
                break
                ;;
            -k|--contents)
                action="contents"
                break
                ;;
            -o|--owner)
                action="owner"
                break
                ;;
            --config)
                action="config"
                break
                ;;
            -V|--version|-I|--info|-h|--help)
                action="info"
                break
                ;;
            --has-version|--best-version|--match)
                action="version_query"
                break
                ;;
            --environment-variable)
                action="env_variable_query"
                break
                ;;
            --configuration-variable)
                action="conf_variable_query"
                break
                ;;
            --list-repositories|--list-categories|--list-packages|--list-sets|--list-sync-protocols|--list-repository-formats|--list-dep-tag-categories)
                action="list"
                break
                ;;
            --regenerate-installed-cache|--regenerate-installable-cache)
                action="regen_repos"
                break
                ;;
        esac
    done

    case "${cur}" in
        -*)
            local opts=
            [[ -z "${action}" ]] && action="all"
            opts="${action}_opts"

            COMPREPLY=($(compgen -W "${general_opts} ${!opts}" -- "${cur}"))
            return 0
            ;;
       *)
            case "${prev}" in
                ## Enum operators
                --log-level)
                    COMPREPLY=($(compgen -W "debug qa warning silent" -- "${cur}"))
                    return 0
                    ;;
                --debug-build)
                    COMPREPLY=($(compgen -W "none split internal" -- "${cur}"))
                    return 0
                    ;;
                --checks)
                    COMPREPLY=($(compgen -W "none default always" -- "${cur}"))
                    return 0
                    ;;
                --show-reasons)
                    COMPREPLY=($(compgen -W "none summary full" -- "${cur}"))
                    return 0
                    ;;
                --show-use-descriptions)
                    COMPREPLY=($(compgen -W "none new changed all" -- "${cur}"))
                    return 0
                    ;;
                --show-package-descriptions)
                    COMPREPLY=($(compgen -W "none new all" -- "${cur}"))
                    return 0
                    ;;
                --continue-on-failure)
                    COMPREPLY=($(compgen -W "if-fetch-only never if-satisfied if-independent always" -- "${cur}"))
                    return 0
                    ;;

                --dl-reinstall)
                    COMPREPLY=($(compgen -W "never always if-use-changed" -- "${cur}"))
                    return 0
                    ;;
                --dl-reinstall-scm)
                    COMPREPLY=($(compgen -W "never always daily weekly" -- "${cur}"))
                    return 0
                    ;;
                --dl-reinstall-targets)
                    COMPREPLY=($(compgen -W "auto never always" -- "${cur}"))
                    return 0
                    ;;
                --dl-upgrade|--dl-new-slots)
                    COMPREPLY=($(compgen -W "always as-needed" -- "${cur}"))
                    return 0
                    ;;
                --dl-downgrade)
                    COMPREPLY=($(compgen -W "as-needed warning error" -- "${cur}"))
                    return 0
                    ;;

                --dl-deps-default|--dl-installed-deps-pre|--dl-installed-deps-runtime|--dl-installed-deps-post|--dl-uninstalled-deps-pre|--dl-uninstalled-deps-runtime|--dl-uninstalled-deps-post|--dl-uninstalled-deps-suggested)
                    COMPREPLY=($(compgen -W "pre pre-or-post post try-post discard" -- "${cur}"))
                    return 0
                    ;;

                --dl-suggested)
                    COMPREPLY=($(compgen -W "show install discard" -- "${cur}"))
                    return 0
                    ;;
                --dl-blocks)
                    COMPREPLY=($(compgen -W "accumulate error discard" -- "${cur}"))
                    return 0
                    ;;
                --dl-override-masks)
                    COMPREPLY=($(compgen -W "none tilde-keyword unkeyworded repository license" -- "${cur}"))
                    return 0
                    ;;

                --dl-circular)
                    COMPREPLY=($(compgen -W "error discard" -- "${cur}"))
                    return 0
                    ;;
                --dl-fall-back)
                    COMPREPLY=($(compgen -W "as-needed-except-targets as-needed never" -- "${cur}"))
                    return 0
                    ;;
                ## list specifiers
                --repository)
                    COMPREPLY=($(compgen -W "$(_paludis_dolist repositories)" -- "${cur}"))
                    return 0
                    ;;
                --repository-format)
                    COMPREPLY=($(compgen -W "$(_paludis_dolist repository-formats)" -- "${cur}"))
                    return 0
                    ;;
                --category)
                    COMPREPLY=($(compgen -W "$(_paludis_dolist categories)" -- "${cur}"))
                    return 0
                    ;;
                --package)
                    COMPREPLY=($(compgen -W "$(_paludis_packagenames "${cur}")" -- "${cur}"))
                    return 0
                    ;;
                --set)
                    COMPREPLY=($(compgen -W "$(_paludis_dolist sets)" -- "${cur}"))
                    return 0
                    ;;
                --owner|-o)
                    _filedir
                    return 0
                    ;;
                #=*|>*|>*|~*)
                #    :
                #    ;;
                *)
                    case "${action}" in
                        sync|regen_repos)
                            COMPREPLY=($(compgen -W "$(_paludis_dolist repositories)" -- "${cur}"))
                            return 0
                            ;;
                        report|info|list)
                            return 0
                            ;;
                        owner)
                            _filedir
                            return 0
                            ;;
                        conf_variable_query)
                            case "${prev}" in
                                -*)
                                    COMPREPLY=($(compgen -W "$(_paludis_dolist repositories)" -- "${cur}"))
                                    ;;
                                *)
                                    COMPREPLY=($(compgen -W "$(paludis --log-level silent --list-repositories --repository ${prev} |sed -n 's,^        \([^:]*\).*,\1,p')" -- "${cur}"))
                                    ;;
                            esac
                            return 0
                            
                            ;;
                        query|install|uninstall|contents|version_query|env_variable_query|config)
                            if [[ "${action}" == "env_variable_query" \
                                && "${prev}" != -* ]]
                            then
                                COMPREPLY=($(compgen -W "$(paludis --log-level silent --info |sed -n 's,^        \([A-Z][^:]*\):.*,\1,p')" -- "${cur}"))
                                return 0
                            fi
                            # default - match on package names
                            case "${cur}" in
                                */*)
                                    local catname=${cur%/*}
                                    COMPREPLY=($(compgen -W "$(paludis --list-packages --log-level silent --category ${catname} |sed -n 's,^\* \(.*\),\1,p')" -- "${cur}"))
                                    return 0
                                    ;;
                                *)
                                    # Do set name, package name, and category name completion
                                    COMPREPLY=(
                                    $(compgen -W "$(_paludis_dolist sets)" -- "${cur}")
                                    $(compgen -W "$(_paludis_dolist categories)" -- "${cur}")
                                    $(compgen -W "$(_paludis_packagenames "${cur}")" -- "${cur}")
                                    )
                                    _filedir
                                    return 0
                                    ;;
                            esac
                            ;;
                    esac
                    ;;
            esac
            ;;
    esac
}
complete -o filenames -F _paludis paludis