aboutsummaryrefslogtreecommitdiff
path: root/zsh-completion/_paludis_packages
blob: 8e70f3183ffb7f812867974ad562381f2582b4ec (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
#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_packages_update_available() {
    if [[ $PREFIX != -* ]]; then
        if [[ $PREFIX != */* ]];then
            if ( [[ ${+_paludis_pkgs_available} -eq 0 ]] || _cache_invalid PALUDIS_available ) && ! _retrieve_cache PALUDIS_available ; then
                _paludis_pkgs_available=(${(o)${${(M)${(f)"$(paludis --log-level silent --list-packages)"}:#\* *}##\* }##*/})
                _store_cache PALUDIS_available _paludis_pkgs_available
            fi
            _wanted paludis_pkgs expl "packages" compadd - ${(@)_paludis_pkgs_avail}
            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
    fi
}

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

_paludis_packages_update_installed() {
    if ( [[ ${+_paludis_pkgs_installed} -eq 0 ]] || _cache_invalid PALUDIS_installed ) && ! _retrieve_cache PALUDIS_installed ; then
        _paludis_pkgs_installed=(${${(M)${(f)"$(paludis --log-level silent --repository installed --list-packages)"}:#\* *}##\* })
        _store_cache PALUDIS_installed _paludis_pkgs_installed
    fi
    compadd ${(@)_paludis_pkgs_inst}
}
_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 "$@"