summaryrefslogtreecommitdiff
path: root/provides/zsh/completions/_pkg
blob: e4ecfff4ca30285e75d41b8defc3b2cad8a26673 (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
#compdef pkg
## vim:ft=zsh
## pkg completion
## Daniel Friesel <derf@derf.homelinux.org>
## https://derf.homelinux.org/~derf/dotfiles/zsh/completions/_pkg
## see also: https://derf.homelinux.org/~derf/code/lighty-stats

typeset expl

function _pkg_action () {
	_wanted action expl 'action' \
	compadd add install changelog changeroot check delete remove info \
	list list-all local-update log push remote-update status update upgrade
}

function _pkg_installed () {
	_wanted package expl 'local package' \
	compadd $(pkg list)
}

function _pkg_all () {
	_wanted package expl 'package' \
	compadd $(pkg list-all)
}

function _pkg_notinstalled () {
	_wanted package expl 'remote package' \
	compadd $(diff <(pkg list) <(pkg list-all) | grep "^>" | cut -d " " -f 2)
}

if (( CURRENT >= 3 )) {
	case ${words[2]} in
		changelog|check|delete|log|push|remove|status|upgrade)
			_arguments -s '2: :_pkg_installed' ;;
		info) _arguments -s '2: :_pkg_all' ;;
		add|install) _arguments -s '2: :_pkg_notinstalled' ;;
	esac
} else {
	_arguments -s '1: :_pkg_action'
}