about summary refs log tree commit diff
path: root/Completion/Mandrake/Command/_urpmi
blob: 76a5375b63277100c5276c9ecf91cf9e7b752284 (plain) (blame)
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
#compdef urpmi urpmi.addmedia urpmi.removemedia urpmi.update

_urpmi_cache_policy() {
    local -a synthesis
    local i
    synthesis=(/var/lib/urpmi/synthesis.*)
    for i in $synthesis; do
	[[ -e "$1" && -e "$i" && "$1" -nt "$i" ]] && return 1
    done
    return 0
}
    
_urpmi() {
    local expl state curcontext="$curcontext" line ret=1
    typeset -A opt_args

    case "$service" in
	urpmi.addmedia )
	    _arguments -C -A '-*' \
		"(--wget)--curl[use curl to retrieve distant files]" \
		"(:)--distrib[automatically create all media from an installation medium]:media URL:->media_url" \
		"--update[mark as update media]" \
		"(--curl)--wget[use wget to retrieve distant files]" \
		"-c[clean headers cache directory]" \
		"-f[force generation of hdlist files]" \
		"-h[try to find and use synthesis or hdlist file]" \
		"(--distrib):name of media: " \
		"(--distrib):media URL:->media_url" \
		"(--distrib): :(with)" \
		"(--distrib):relative path to hdlist file: " \
	     && ret=0
	;;
	urpmi.removemedia )
	    _arguments -C -A '-*' \
		"(:)-a[select all media]" \
		"(-a)"{,\*}": :->urpmi_media" \
	     && ret=0
	;;
	urpmi.update )
	    _arguments -C -A '-*' \
		"(--wget)--curl[use curl to retrieve distant files]" \
		"(--curl)--wget[use wget to retrieve distant files]" \
		"(:)-a[select all non-removable media]" \
		"-c[clean /var/cache/urpmi/headers on exit]" \
		"-d[force complete computation of depslist.ordered file]" \
		"*-f[force generation of hdlist files]" \
		"(-a)"{,\*}": :->urpmi_media" \
	     && ret=0
	;;
	urpmi )
	    _arguments -C -A '-*' \
		"(: -)--help[print usage information]" \
		"(--help)--allow-medium-change[allow change of removable media]" \
		"(--help)--auto[do not ask any questions]" \
		"(--help)--auto-select[select the packages to update]" \
		"(--help -X)--best-output[automatically select text or X interface]" \
		"(--help)--complete[use parsehdlist server to complete selection]" \
		"(--help --wget)--curl[use curl to retrieve distant files]" \
		"(--help)--force[proceed even when some packages do not exist]" \
		"(--help)--update[use only update media]" \
		"(--help --curl)--wget[use wget to retrieve distant files]" \
		"(--help)-a[select all packages matching command line]" \
		"(--help -m -M)-m[choose minimum closure of requires (default)]" \
		"(--help -m -M)-M[choose maximum closure of requires]" \
		"(--help)-p[allow search in provides]" \
		"(--help -q -v)-q[be quiet]" \
		"(--help -q -v)-v[verbose mode]" \
		"(--help --best-output)-X[use X interface]" \
		"(--help)"{,\*}": :->urpmi_rpms" \
	    && ret=0
	;;
    esac

    case "$state" in
	media_url )
	    if compset -P file:// || compset -P removable://; then
		_files -W / -/ && ret=0
	    elif [[ -prefix '(ftp|http)://' ]]; then
		_urls && ret=0
	    else
		_wanted urpmi_media_type expl 'type of media' \
		    compadd -- file:// http:// ftp:// removable:// && ret=0
	    fi
	;;
	urpmi_media )
	    local source media brace ret=1
	    while read source media brace; do
		[[ "$brace" != "{" ]] && continue
		_wanted urpmi_media expl 'available media' \
		    compadd -- "$source"
		ret=0
	    done < /etc/urpmi/urpmi.cfg
	;;
	urpmi_rpms )
	    local pkg foo expl
	    local -a pkgs
	    local -a synthesis
	    synthesis=(/var/lib/urpmi/synthesis.*(N))
	    (( $#synthesis > 0 )) && {
		if _cache_invalid _urpmi_rpms || ! _retrieve_cache _urpmi_rpms; then
		    pkgs=($(zcat $synthesis | \
			 grep @info@ | cut -d @ -f 3 | sed -e 's/\.[^.]*$//'))
		    _store_cache _urpmi_rpms pkgs
		fi
	    }
	    (( $#pkgs > 0 )) && \
		_wanted urpmi_rpms expl 'urpmi RPMs to install' \
		    compadd -a pkgs && ret=0
	    (( $EUID == 0 )) && \
		_wanted urpmi_files expl 'RPM files to install' \
		    _files -g '*.(#i)rpm' && ret=0
	;;
    esac

    return $ret
}

local update_policy

zstyle -s ":completion:*:*:urpmi:*" cache-policy update_policy
if [[ -z "$update_policy" ]]; then
    zstyle ":completion:*:*:urpmi:*" cache-policy _urpmi_cache_policy
fi

_urpmi "$@"