aboutsummaryrefslogtreecommitdiff
path: root/zsh-completion/_paludis_packages
blob: 35d4e30252dbc29c5ba807e2622a865bb7dd8005 (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
#autoload

# vim: set et sw=4 sts=4 ts=4 ft=zsh :
# ZSH completion utility functions for paludis
# Written by Baptiste Daroussin <baptux at free.fr>
# Usage: _paludis_packages installed|available|repositories|categories|sets|repository-formats

local flags prepo packages categories paludis_pkgs
_paludis_packages_update_available() {
    if [[ $PREFIX != */* ]];then
        paludis_pkgs=(${(o)${${(M)${(f)"$(paludis --log-level silent --list-packages)"}:#\* *}##\* }##*/})
        _wanted paludis_pkgs expl "packages" compadd - ${(@)paludis_pkgs}
        categories=(${${(M)${(f)"$(paludis --log-level silent --list-categories)"}:#\* *}##\* })
        _wanted cat_packages expl "category/packages" compadd -S "/" $categories
    else
        compset -P '*/'
        packages=(${${${(M)${(f)"$(paludis --log-level silent --category ${IPREFIX//\//} --list-packages)"}:#\* *}##\* }//$IPREFIX/})
        _wanted cat_packages expl "category/packages" compadd ${(@)packages}
    fi
}

_paludis_packages_update_repository-formats() {
    packages=(${${(M)${(f)"$(paludis --log-level silent --list-repository-formats)"}:#\* *}##\* })
    compadd ${(@)packages}
}

_paludis_packages_update_installed() {
    packages=(${${(M)${(f)"$(paludis --log-level silent --repository installed --list-packages)"}:#\* *}##\* })
    compadd ${(@)packages}
}
_paludis_packages_update_categories() {
    packages=(${${${(M)${(f)"$(paludis --log-level silent --list-categories)"}:#\* *}##\* }:#*(virtual|installed)*})
    compadd ${(@)packages}
}
_paludis_packages_update_repositories() {
    packages=(${${${(M)${(f)"$(paludis --log-level silent --list-repositories)"}:#\* *}##\* }:#*(virtual|installed)*})
    compadd ${(@)packages}
}
_paludis_packages_update_sets() {
    packages=(${${${(M)${(f)"$(paludis --log-level silent --list-sets)"}:#\* *}##\* }:#*(virtual|installed)*})
    compadd ${(@)packages}
}
_paludis_packages() {
    local command="$argv[$#]" expl cachevar pkgset update_policy
    zstyle -s ":completion:*:*:$service:*" cache-policy update_policy
    if [[ -z "$update_policy" ]]; then
        zstyle ":completion:*:*:$service:*" cache-policy _paludis_cache_policy
    fi
    [[ "$command" == (installed|available|categories|repositories|sets|repository-formats) ]] || {
        _message "unknown command: $command"
        return
    }
    [[ "$pkgset" ==  (installed|available|categories|repositories|sets|repository-formats) ]] || {
        pkgset="$command"
    }
    expl=("${(@)argv[1,-2]}")
        _paludis_packages_update_$pkgset
}
_paludis_cache_policy () {
#   rebuild if cache is more than a week old
        oldp=( "$1"(mw+1) )
        (( $#oldp )) && return 0
}

_paludis_packages "$@"