summaryrefslogtreecommitdiff
blob: 37faa6af418dae0fa85de4a7b4e7f6683d543a90 (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
#compdef gensync equery qpkg

# Author: oberyno <oberyno@gmail.com>

#Function to show gensync overlays located in /etc/gensync
_overlays(){
    overlay=$(grep -h id= /etc/gensync/* | sed -e 's/id="\(.*\)"$/\1/')
    _tags overlay && { compadd "$@" ${(kv)=overlay} }
}

#show portage categories without / at end; app-cdr instead of app-cdr/ -- this can probably be done with _files, but I'm lazy
_category(){
 categories=($portdir/metadata/cache/*-*)
    category=${(M)${${categories##*/}}}
_tags -s category && { compadd "$@" ${(kv)=category} }
}

#Function to show only installed packages   -- pkgname (no category or version #)
_portage_installed(){
    installed_portage=(/var/db/pkg/*-*/*)
    installed_pkgname=${(M)${${installed_portage##*/}%%-[0-9]*}}
    _tags -s installed_pkgname && { compadd "$@" ${(kv)=installed_pkgname} }
}
#moved out of equery 
_equery_val(){
    _values  "equery actions" \
	'files[list files owned by pkg]' \
	'list[list all packages matching pattern]' \
	'belongs[list all packages owning file]' \
	'uses[display USE flags for package]' \
	'which[print full path to ebuild for package]' \
	'depgraph[display a dependency tree for package]' \
	'check[check files against recorded md5sums and timestamps]' \
	'size[print size of files contained in package]' 
	}

#Function to show all available portage names
_portage_pkglist(){
    portage_pkglist="$portage_pkglist"
    _tags -s portage_pkglist && { compadd "$@" ${(kv)=portage_pkglist} }
    _path_files -/ -F "*CVSROOT" -F "*eclass" -F "*distfiles" -F "*licences" -W "${portdir}"
}

#Reading informations from Portage
portdir="$(portageq portdir)"
#pkgdir="$(portageq pkgdir)"
portdir_overlay="$(portageq portdir_overlay)"

portage_pkglist=(${portdir}/*-*/* ${portdir_overlay}/*-*/*)
portage_pkglist=(${portage_pkglist##*/})


case $service in

  gensync) 
      _arguments \
 	'(- :)'{--list-sources,-l}'[list known rsync sources]' \
	'()'{--no-color,-C}'[turn off colours]:overlays:_overlays' \
	'(- :)'{--help,-h}'[show help]' \
	'(- :)'{--version,-V}'[display version info]' \
	'(- :)'':overlays:_overlays' 
;;

 qpkg)
  excl=( --help -h --query-deps -q )
  check=( --check-md5 -cm --check-time -ct --check -c )
  arg=( --info -i --list -l --non-masked -n --masked -m --installed -I --uninstalled -U --group -g )
  find=( --find-file -f --find-pattern -fp )
  dups=( --dups -d --slot -s)
  
       _arguments \
    	"($check $excl $find $dups 1)"{--find-file,-f}"[finds package that owns file]:file:_files" \
	"($check $excl $find $dups 1)"{--find-pattern,-fp}"[finds package that owns file matching pattern]:pattern:" \
	"($excl $check $arg $find --dups -d )"{--dups,-d}"[print packages that have multiple versions installed]" \
	"($excl $check $arg $find --slot -s 1)"{--slot,-s}"[only print duplicates of the same slot]" \
	"($check $excl --installed -I --uninstalled -U $dups -d)"{--uninstalled,-U}"[include only uninstalled packages]" \
	"($excl --uninstalled -U --installed -I $dups -d)"{--installed,-I}"[include only installed packages]" \
	"($excl --group -g $dups -d)"{--group,-g}"[find by group]:group:_category" \
	"($check $excl --list -l $dups -d)"{--list,-l}"[list package contents]" \
	"($excl --info -i $dups -d 1)"{--info,-i}"[get package description and home page]:package:_portage_pkglist" \
	"($excl $check $find $dups --uninstalled -U)"{--check-time,-ct}"[verify package file timestamps]" \
	"($excl $check $find $dups --uninstalled -U)"{--check-md5,-cm}"[verify package files md5]" \
	"($excl $check $find $dups --uninstalled -U)"{--check,-c}"[verify mtimes and md5]" \
	"($excl $find --query-deps -q $dups -d 1)"{--query-deps,-q}"[display all installed packages depending on selected packages]:package:_portage_pkglist" \
	"()"{--no-color,-nc}"[dont use colors]" \
	"*--verbose[be more verbose (2 levels)]" \
	"*-v[be more verbose (2 levels)]" \
	"($excl --non-masked -n --masked -m $dups)"{--masked,-m}"[include only masked packages]" \
	"($excl --non-masked -n --masked -m $dups)"{--non-masked,-n}"[include only non-masked packages]" \
	"(- :)"{--help,-h}"[show help]" \
	"(--info -i --query-deps -q --slot -s)1:package:_portage_installed"
;;
 
equery)
   local prev="$words[CURRENT-1]" prev2="$words[CURRENT-2]" 

   if (( CURRENT == 2 ));then
  	    _equery_val
	    _arguments \
 	$common_args && return 0
   elif (( CURRENT > 2 ));then

        case "$prev" in
	    files|--timestamp|--md5sum|--type)
	    	_arguments -s \
		 '--timestamp[append timestamp]' \
		 '--md5sum[append md5sum]' \
		 '--type[prepend file type]' \
		 '*:installed pkgname:_portage_installed' && return 0
		;;
	    belongs|--earlyout)
		  _arguments -s \
		  '(-c --category)'{-c,--category}'[only search in specified category]' \
		  '(-e --earlyout)'{-e,--earlyout}'[stop when first match found]' \
		  '*:file:_files' && return 0 	 
		;;
	    --category|-c)  
	    	_arguments -s \
			'*:category:_category' && return 0
	    ;;
 	    list|--installed|-i|--exclude-installed|-I|-p|--portage-tree|-o|--overlay-tree)
	    	_arguments -s \
		 '(-i --installed -I --exclude-installed)'{-i,--installed}'[search installed packages]' \
		 '(-I --exclude-installed -i --installed)'{-I,--exclude-installed}'[do not search installed packages]' \
		 '(-p --portage)'{-p,--portage-tree}'[also search in portage tree]' \
		 '(-o --overlay-tree)'{-o,--overlay-tree}'[also search in overlay tree]' \
		 '*:package:_portage_installed' && return 0
		;;
	    uses|which)
	    	_arguments \
		'*:package:_portage_pkglist' \
		     && return 0
		;;
	    depgraph|-U|--no-useflags|-l|--linear)
	    	_arguments -s \
		'(-U --no-useflags)'{-U,--no-useflags}'[do not show USE flags]' \
		'(-l --linear)'{-l,--linear}'[do not use fancy formatting]' \
		 '*:package:_portage_installed' \
		   && return 0
		;;
	    size|-b|--bytes)
	    	_arguments -s \
		'(-b --bytes)'{-b,--bytes}'[report size in bytes]' \
		'*:package:_portage_installed' \
		    && return 0
		;;
	    check)
		_arguments -s \
		'*:package:_portage_installed' \
		    && return 0
	        ;;
	    --nocolor|-C|--quiet|-q)
	    	 _equery_val
		 _arguments \
 		$common_args && return 0
	;;
        esac

	[[ $prev2 == (--category|-c) ]] &&
		_arguments  '(-c --category)'{-c,--category}'[only search in specified category]' \
		  '(-e --earlyout)'{-e,--earlyout}'[stop when first match found]' \
		  '*:file:_files'  && return 0 

   fi
   common_args=(
 	{'(--nocolor)-C','(-C)--nocolor'}'[turns off colors]'
	{'(--quiet)-q','(-q)--quiet'}'[minimal output]'
	{'(--help)-h','(-h)--help'}'[show help]'
 )
 ;;
esac