summaryrefslogtreecommitdiff
path: root/provides/zsh/completions/_pkg
blob: abcb8d1f70630050e18a0cc6012ec6f0b667eea2 (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
#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 check delete eval remove info 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 == 2 )) {
	_pkg_action
} elif (( CURRENT == 3 )) {
	case ${words[2]} in
		changelog|check|delete|log|push|remove|status|upgrade)
			_pkg_installed
		;;
		info)
			_pkg_all 
		;;
		add|install)
			_pkg_notinstalled
		;;
		eval)
			_message 'shell code for evaluation'
			_wanted function expl 'internal function' \
			compadd $(grep -E '^\S*\s*\(\)\s*{' ~/bin/pkg | cut -d ' ' -f 1)
		;;
		*)
			_message 'no more arguments'
		;;
	esac
} elif [[ ${words[2]} = 'eval' ]] {
	_message 'shell code for evaluation'
	if (( CURRENT == 4 )) {
		case ${words[3]} in
			exec_hook|check_prereqs|*_collected|)
				_pkg_installed
			;;
		esac
	} elif (( CURRENT == 5 )) {
		case ${words[3]} in
			exec_hook)
				_wanted hook expl 'package hook' \
				compadd $(ls -1 ~/packages/${words[4]}/hooks 2> /dev/null)
			;;
		esac
	}
} else {
	_message 'no more arguments'
}