about summary refs log tree commit diff
path: root/Completion
diff options
context:
space:
mode:
Diffstat (limited to 'Completion')
-rw-r--r--Completion/Solaris/Command/.distfiles15
-rw-r--r--Completion/Solaris/Command/_coreadm48
-rw-r--r--Completion/Solaris/Command/_dhcpinfo36
-rw-r--r--Completion/Solaris/Command/_dumpadm23
-rw-r--r--Completion/Solaris/Command/_gcore31
-rw-r--r--Completion/Solaris/Command/_inetadm16
-rw-r--r--Completion/Solaris/Command/_pfexec31
-rw-r--r--Completion/Solaris/Command/_ptree23
-rw-r--r--Completion/Solaris/Command/_savecore12
-rw-r--r--Completion/Solaris/Command/_svcadm70
-rw-r--r--Completion/Solaris/Command/_svccfg58
-rw-r--r--Completion/Solaris/Command/_svcprop23
-rw-r--r--Completion/Solaris/Command/_svcs32
-rw-r--r--Completion/Solaris/Command/_zlogin16
-rw-r--r--Completion/Solaris/Type/.distfiles3
-rw-r--r--Completion/Solaris/Type/_svcs_fmri82
-rw-r--r--Completion/Unix/Command/.distfiles6
-rw-r--r--Completion/Unix/Command/_pkg_instance20
-rw-r--r--Completion/Unix/Command/_pkgadd32
-rw-r--r--Completion/Unix/Command/_pkginfo22
-rw-r--r--Completion/Unix/Command/_pkgrm20
-rw-r--r--Completion/Unix/Command/_zfs238
-rw-r--r--Completion/Unix/Command/_zpool201
-rw-r--r--Completion/Unix/Type/.distfiles2
-rw-r--r--Completion/Unix/Type/_zfs_dataset22
-rw-r--r--Completion/Unix/Type/_zfs_pool3
26 files changed, 1085 insertions, 0 deletions
diff --git a/Completion/Solaris/Command/.distfiles b/Completion/Solaris/Command/.distfiles
new file mode 100644
index 000000000..3c606773b
--- /dev/null
+++ b/Completion/Solaris/Command/.distfiles
@@ -0,0 +1,15 @@
+DISTFILES_SRC='
+_coreadm
+_dhcpinfo
+_dumpadm
+_gcore
+_inetadm
+_pfexec
+_ptree
+_savecore
+_svcadm
+_svccfg
+_svcprop
+_svcs
+_zlogin
+'
diff --git a/Completion/Solaris/Command/_coreadm b/Completion/Solaris/Command/_coreadm
new file mode 100644
index 000000000..7cf529a4f
--- /dev/null
+++ b/Completion/Solaris/Command/_coreadm
@@ -0,0 +1,48 @@
+#compdef coreadm
+
+_coreadm() {
+	local -a content option
+
+	content=(
+		"anon[Anonymous private mappings]"
+		"ctf[CTF type information]"
+		"data[Writable private file mappings]"
+		"dism[DISM mappings]"
+		"heap[Process heap]"
+		"ism[ISM mappings]"
+		"rodata[Read-only private file mappings]"
+		"shanon[Anonymous shared mappings]"
+		"shfile[File-backed shared mappings]"
+		"shm[System V shared memory]"
+		"stack[Process stack]"
+		"symtab[Symbol table sections for loaded files]"
+		"text[Readable and executable private file mappings]"
+	)
+
+	option=(
+		"global"\:"Allow global core dumps"
+		"global-setid"\:"Allow set-id global core dumps"
+		"log"\:"Generate a syslog message on global core dump"
+		"process"\:"Allow per-process core dumps"
+		"proc-setid"\:"Allow set-id per-process core dumps"
+	)
+
+	# _values doesn't quite work for us here -- the separator can be either
+	# "+" or "-"
+	_arguments -s \
+		- set1 \
+		'-g[Global core file name pattern]:' \
+		'-G[Global core file content]:content:_values -s + "content" $content' \
+		'-i[Per-process core file name pattern]:' \
+		'-I[Per-process core file content]:content:_values -s + "content" $content' \
+		'*-d[Disable core option]:option:(($option))' \
+		'*-e[Enable core option]:option:(($option))' \
+		- set2 \
+		'-p[PID-specific per-process core file name pattern]:' \
+		'-P[PID-specific per-process core file content]:content:_values -s + "content" $content' \
+		'*:pids:_pids' \
+		- set3 \
+		'-u[Update options from coreadm.conf]'
+}
+
+_coreadm "$@"
diff --git a/Completion/Solaris/Command/_dhcpinfo b/Completion/Solaris/Command/_dhcpinfo
new file mode 100644
index 000000000..076b015b7
--- /dev/null
+++ b/Completion/Solaris/Command/_dhcpinfo
@@ -0,0 +1,36 @@
+#compdef dhcpinfo
+
+_dhcpinfo() {
+	local -a mnemonics_v4 mnemonics_v6
+
+	mnemonics_v4=(
+		Subnet UTCoffst Router Timeserv IEN116ns DNSserv Logserv
+		Cookie Lprserv Impress Resource Hostname Bootsize Dumpfile
+		DNSdmain Swapserv Rootpath ExtendP IpFwdF NLrouteF PFilter
+		MaxIpSiz IpTTL PathTO PathTbl MTU SameMtuF Broadcst
+		MaskDscF MaskSupF RDiscvyF RSolictS StaticRt TrailerF
+		ArpTimeO EthEncap TcpTTL TcpKaInt TcpKaGbF NISdmain
+		NISservs NTPservs NetBNms NetBDsts NetBNdT NetBScop
+		XFontSrv XDispMgr LeaseTim Message T1Time T2Time NW_dmain
+		NWIPOpts NIS+dom NIS+serv TFTPsrvN OptBootF MblIPAgt
+		OptBootF MblIPAgt SMTPserv POP3serv NNTPserv WWWservs
+		Fingersv IRCservs STservs STDAservs UserClas SLP_DA SLP_SS
+		AgentOpt FQDN PXEarch BootFile BootPath BootSrvA BootSrvN
+		EchoVC LeaseNeg
+	)
+
+	mnemonics_v6=(
+		ClientID ServerID Preference Unicast UserClass VendorClass
+		SIPNames SIPAddresses DNSAddresses DNSSearch NISServers
+		NIS+Servers NISDomain NIS+Domain SNTPServers InfoRefresh
+		BCMCDomain BCMCAddresses
+	)
+
+	_arguments -A \
+		'-c[]' \
+		'-i[Interface]:interface:' \
+		'-n[Maximum number of lines]:limit:' \
+		':DHCP Parameter:_values "DHCP Parameter" $mnemonics_v4' \
+}
+
+_dhcpinfo "$@"
diff --git a/Completion/Solaris/Command/_dumpadm b/Completion/Solaris/Command/_dumpadm
new file mode 100644
index 000000000..37491946c
--- /dev/null
+++ b/Completion/Solaris/Command/_dumpadm
@@ -0,0 +1,23 @@
+#compdef dumpadm
+
+_dumpadm() {
+	local -a content
+
+	content=(
+		"kernel"\:"Kernel memory pages only"
+		"all"\:"All memory pages"
+		"curproc"\:"Kernel memory pages plus curproc pages"
+	)
+
+	_arguments -s \
+		'-n[Dont run savecore on reboot]' \
+		'-u[Update dump configuration from dumpadm.conf]' \
+		'-y[Run savecore on reboot]' \
+		'-c[Set dump content]:dump content:(($content))' \
+		'-d[Set dump device]:block devices:_files -g "*(-%b)"' \
+		'-m[Set minfree size ]:' \
+		'-s[Set the savecore directory]:directory:_files -/' \
+		'-r[Alternate root directory]:directory:_files -/'
+}
+
+_dumpadm "$@"
diff --git a/Completion/Solaris/Command/_gcore b/Completion/Solaris/Command/_gcore
new file mode 100644
index 000000000..c7b8d9466
--- /dev/null
+++ b/Completion/Solaris/Command/_gcore
@@ -0,0 +1,31 @@
+#compdef gcore
+
+_gcore() {
+	local -a content
+
+	content=(
+		"anon[Anonymous private mappings]"
+		"ctf[CTF type information]"
+		"data[Writable private file mappings]"
+		"dism[DISM mappings]"
+		"heap[Process heap]"
+		"ism[ISM mappings]"
+		"rodata[Read-only private file mappings]"
+		"shanon[Anonymous shared mappings]"
+		"shfile[File-backed shared mappings]"
+		"shm[System V shared memory]"
+		"stack[Process stack]"
+		"symtab[Symbol table sections for loaded files]"
+		"text[Readable and executable private file mappings]"
+	)
+
+	_arguments -s \
+		'-p[Use per-process core file repository]' \
+		'-g[Use global core file repository]' \
+		'-F[Force grabbing the target process]' \
+		'-c[Set core file content]:_values -s + "content" $content' \
+		'-o[Set core file base name]:' \
+		'*:pids:_pids'
+}
+
+_gcore "$@"
diff --git a/Completion/Solaris/Command/_inetadm b/Completion/Solaris/Command/_inetadm
new file mode 100644
index 000000000..2588672ef
--- /dev/null
+++ b/Completion/Solaris/Command/_inetadm
@@ -0,0 +1,16 @@
+#compdef inetadm
+
+_inetadm() {
+	_arguments -s \
+		'-?[Help]' \
+		'-l[List service instance properties]:FMRI:_svcs_fmri -i' \
+		'-e[Enable specified instance]:FMRI:_svcs_fmri -i' \
+		'-d[Disable specified instance]:FMRI:_svcs_fmri -i' \
+		'-p[List inet service properties]' \
+		'-m[Modify service instance properties]:FMRI:_svcs_fmri -i' \
+		'-M[Modify inet service properties]'
+}
+
+_inetadm "$@"
+
+# vi:tw=0
diff --git a/Completion/Solaris/Command/_pfexec b/Completion/Solaris/Command/_pfexec
new file mode 100644
index 000000000..227336223
--- /dev/null
+++ b/Completion/Solaris/Command/_pfexec
@@ -0,0 +1,31 @@
+#compdef pfexec
+
+# This is a _values-like function that completes privileges and !-prefixed
+# privileges, comma-separated, and unique.
+_privset() {
+	local expl p
+	local -a privs
+
+	privs=( ${(f)"$(ppriv -l)"} all none zone basic )
+
+	# Ignore existing values
+	compset -P '*,'
+	# Ignore a leading !, maybe backslash-quoted
+	compset -P '\\#!'
+
+	# Remove already-referenced privs
+	for p in ${(s:,:)${IPREFIX//\\#\!/}}; do
+		privs=( ${privs:#$p} )
+	done
+
+	_wanted privs expl 'privilege' compadd -qS , -a privs
+}
+
+_pfexec() {
+ 	_arguments \
+		'-P[privileges to acquire]:privspec:_privset' \
+ 		'(-):command name: _command_names -e' \
+ 		'*::arguments: _normal'
+}
+
+_pfexec "$@"
diff --git a/Completion/Solaris/Command/_ptree b/Completion/Solaris/Command/_ptree
new file mode 100644
index 000000000..c75a211c4
--- /dev/null
+++ b/Completion/Solaris/Command/_ptree
@@ -0,0 +1,23 @@
+#compdef ptree
+
+_ptree() {
+	local curcontext="$curcontext" context state line ret=1
+	typeset -A opt_args
+
+	_arguments -s \
+		'-a[All processes]' \
+		'-c[Show contract memberships]' \
+		'-z[Show processes in zone]:zone:($(zoneadm list))' \
+		'*:pid or user:->pidoruser' && ret=0
+
+	if [[ $ret -ne 0 ]]; then
+		_alternative \
+			'users:logged-in user:(${$(who -q)\:#(users=*|\#)})' \
+			'pids:pid:_pids'
+		ret=$?
+	fi
+
+	return $ret
+}
+
+_ptree "$@"
diff --git a/Completion/Solaris/Command/_savecore b/Completion/Solaris/Command/_savecore
new file mode 100644
index 000000000..63bb81fb7
--- /dev/null
+++ b/Completion/Solaris/Command/_savecore
@@ -0,0 +1,12 @@
+#compdef savecore
+
+_savecore() {
+	_arguments -s \
+		'-L[Take live dump]' \
+		'-v[Verbose]' \
+		'-d[Disregard dump header valid flag]' \
+		'-f[Save crash dump from file]:file:_files' \
+		'::directory:_files -/'
+}
+
+_savecore "$@"
diff --git a/Completion/Solaris/Command/_svcadm b/Completion/Solaris/Command/_svcadm
new file mode 100644
index 000000000..c2e91a6fe
--- /dev/null
+++ b/Completion/Solaris/Command/_svcadm
@@ -0,0 +1,70 @@
+#compdef svcadm
+
+_svcadm() {
+	local context state line subcmds
+	typeset -A opt_args
+
+	subcmds=( enable disable restart refresh mark clear milestone )
+
+	if [[ $service == "svcadm" ]]; then
+		_arguments -C -A "-*" \
+			'-v[Print actions verbosely]' \
+			'*::command:->subcmd' && return 0
+
+		if (( CURRENT == 1 )); then
+			_wanted commands expl 'svcadm subcommand' compadd -a subcmds
+			return
+		fi
+		service="$words[1]"
+		curcontext="${curcontext%:*}=$service:"
+	fi
+
+	case $service in
+	(enable)
+		_arguments \
+			'-r[Recursively enable dependencies]' \
+			'-s[Wait for service to come online]' \
+			'-t[State change is temporary]' \
+			'*:instance FMRI:_svcs_fmri -i'
+		;;
+
+	(disable)
+		_arguments \
+			'-s[Wait for service to become disabled]' \
+			'-t[State change is temporary]' \
+			'*:instance FMRI:_svcs_fmri -i'
+		;;
+
+	(mark)
+		_arguments \
+			'-I[Change state immediately]' \
+			'-t[State change is temporary]' \
+			':state:(degraded maintenance)' \
+			':instance FMRI:_svcs_fmri -i'
+		;;
+
+	(restart|refresh|clear)
+		_arguments \
+			'*:instance FMRI:_svcs_fmri -i'
+		;;
+
+	(milestone)
+		_arguments \
+			'-d[Make milestone the default]' \
+			'*:milestone FMRI:_svcs_fmri -m'
+		;;
+
+# 	# The delegate subcommand has been removed, replaced by just using
+# 	# the restarter fmri
+# 	(delegate)
+# 		_arguments \
+# 			'1:restarter FMRI:_svcs_fmri -r' \
+# 			'*:instance FMRI:_svcs_fmri -i'
+# 		;;
+
+	(*)
+		_message "unknown svcadm subcommand: $service"
+	esac
+}
+
+_svcadm "$@"
diff --git a/Completion/Solaris/Command/_svccfg b/Completion/Solaris/Command/_svccfg
new file mode 100644
index 000000000..59f275f26
--- /dev/null
+++ b/Completion/Solaris/Command/_svccfg
@@ -0,0 +1,58 @@
+#compdef svccfg
+
+_svccfg() {
+	local context state line subcmds
+
+	subcmds=( apply extract import validate export inventory delete addpropvalue delpropvalue )
+
+	if [[ $service == "svccfg" ]]; then
+		_arguments -s \
+			'-?[Help]' \
+			'-v[Verbose]' \
+			'-s[FMRI on which to operate]:fmri:_svcs_fmri -c' \
+			- set1 \
+			'-f[Read commands from file]:command file:_files' \
+			- set2 \
+			'*::command:->subcmd' && return 0
+
+		if (( CURRENT == 1 )); then
+			_wanted commands expl 'svccfg subcommand' compadd -a subcmds
+			return
+		fi
+		service="$words[1]"
+		curcontext="${curcontext%:*}=$service:"
+	fi
+
+	case $service in
+	(import)
+		_arguments \
+			'-V[Verify property updates]' \
+			':file:_files'
+		;;
+
+	(apply|validate|inventory)
+		_files
+		;;
+
+	(export)
+		_svcs_fmri -c
+		;;
+
+	(delete)
+		_arguments \
+			'-f[Force deletion if online or degraded]' \
+			'*:FMRI:_svcs_fmri -c'
+		;;
+
+	(extract)
+		;;
+
+	(*)
+		_message "unknown svccfg subcommand: $service"
+		;;
+	esac
+}
+
+_svccfg "$@"
+
+# vi:tw=0
diff --git a/Completion/Solaris/Command/_svcprop b/Completion/Solaris/Command/_svcprop
new file mode 100644
index 000000000..aa166808a
--- /dev/null
+++ b/Completion/Solaris/Command/_svcprop
@@ -0,0 +1,23 @@
+#compdef svcprop
+
+_svcprop() {
+	_arguments -s \
+		'-f[Designate properties by their FMRI]' \
+		'-q[Quiet]' \
+		'-t[Use multi-property output format]' \
+		'-v[Verbose]' \
+		- set1 \
+		'-w[Waits for the selected property or property group to change]' \
+		'-p[Prints values of named property or property group]' \
+		':FMRI:_svcs_fmri -i' \
+		- set2 \
+		'(-c -s)-C[Retrieve properties without composition]' \
+		'(-C -s)-c[Retrieve properties with composition]' \
+		'(-c -C)-s[Retrieve properties from snapshot]:snapshot:' \
+		'*-p[Prints values of named property or property group]' \
+		'*:FMRI:_svcs_fmri -i'
+}
+
+_svcprop "$@"
+
+# vi:tw=0
diff --git a/Completion/Solaris/Command/_svcs b/Completion/Solaris/Command/_svcs
new file mode 100644
index 000000000..0fcad2628
--- /dev/null
+++ b/Completion/Solaris/Command/_svcs
@@ -0,0 +1,32 @@
+#compdef svcs
+
+_svcs() {
+	local -a cols
+
+	cols=(
+		ctid\:"Contract ID" desc\:"Description" fmri\:"FMRI"
+		inst\:"Instance name" nsta\:"Next state (abbr)" nstate\:"Next state"
+		scope\:"Scope name" svc\:"Service name" sta\:"State (abbr)"
+		state\:"State" stime\:"Start time"
+	)
+
+	_arguments -s \
+		'(-l -x -d -D)-a[List all instances]' \
+		'(-l -x -D -a -R)-d[List dependencies]' \
+		'(-l -x -d -a -R)-D[List dependents]' \
+		'(-l -x)-H[Suppress header line]' \
+		'(-)-l[Print detailed status about services and instances]' \
+		'(-l -x)-o[Display specific columns]:column:_values -s , "column" ${^cols/\:/[}\]' \
+		'(-l -x)-p[List processes]' \
+		'(-l -x -d -D)-R[List services with the given restarter]:instance FMRI:_svcs_fmri -i' \
+		'(-l -x)-s[Sort by a column]:column:(($cols))' \
+		'(-l -x)-S[Reverse sort by a column]:column:(($cols))' \
+		'(-l)-v[verbose columns]' \
+		'(-l)-x[Display explanation for service states]' \
+		'(-l -x)-\?[Print help]' \
+		'*:FMRI or pattern:_svcs_fmri -i'
+}
+
+_svcs "$@"
+
+# vi:tw=0
diff --git a/Completion/Solaris/Command/_zlogin b/Completion/Solaris/Command/_zlogin
new file mode 100644
index 000000000..9e93684b8
--- /dev/null
+++ b/Completion/Solaris/Command/_zlogin
@@ -0,0 +1,16 @@
+#compdef zlogin
+
+_zlogin() {
+	_arguments -s \
+		'-E[Disable escape character]' \
+		'-e[Specify escape character]:character:' \
+		'-l[Specify username]:username:_users' \
+		':zonename:' \
+		- set1 \
+		'-C[Connect to zone console]' \
+		- set2 \
+		'-S["Safe" login mode]' \
+		':utility'
+}
+
+_zlogin "$@"
diff --git a/Completion/Solaris/Type/.distfiles b/Completion/Solaris/Type/.distfiles
new file mode 100644
index 000000000..cbe93b813
--- /dev/null
+++ b/Completion/Solaris/Type/.distfiles
@@ -0,0 +1,3 @@
+DISTFILES_SRC='
+_svcs_fmri
+'
diff --git a/Completion/Solaris/Type/_svcs_fmri b/Completion/Solaris/Type/_svcs_fmri
new file mode 100644
index 000000000..684dc8d6d
--- /dev/null
+++ b/Completion/Solaris/Type/_svcs_fmri
@@ -0,0 +1,82 @@
+#autoload
+
+_svcs_fmri() {
+	local type="$argv[$#]"
+	local fmri_abbrevs m i
+	typeset -a -g _smf_fmris
+
+	local update_policy
+	zstyle -s ":completion:${curcontext}:" cache-policy update_policy
+	if [[ -z "$update_policy" ]]; then
+		zstyle ":completion:${curcontext}:" cache-policy _smf_caching_policy
+	fi
+	# The cache really must be per-host
+	local cache_id=smf_fmri:$HOST
+
+	# TODO: Do something useful with the expand and/or ambiguous styles.
+	case $type in
+	(-i|-c)
+		# We probably also need an option to eliminate ambiguous
+		# results for use in places where that's not allowed.
+
+		# Grab all FMRIs that have a word beginning with $PREFIX,
+		# making sure not to return the portion of the FMRI before
+		# $PREFIX.  Use the cache if it exists and the user wants to.
+		if ( [[ $#_smf_fmris -eq 0 ]] || _cache_invalid $cache_id ) && ! _retrieve_cache $cache_id; then
+			_smf_fmris=( ${(f)"$(svcs -a -H -o fmri)"} )
+			_store_cache $cache_id _smf_fmris
+		fi
+		# Each element of the array is removed which doesn't match (^|.*/)$PREFIX.*
+		fmri_abbrevs=( ${(M)_smf_fmris:#((#s)|*[/:])$PREFIX*} )
+
+		# Go through the remaining elements and remove the characters
+		# in front of $PREFIX.
+		for i in {1..$#fmri_abbrevs}; do
+			# Either one of these will work, but they're too
+			# greedy, preventing multiple matches below.
+			fmri_abbrevs[i]=${${fmri_abbrevs[i]}/((#s)|*[\/:])(#b)($PREFIX*)/$match[1]}
+			#fmri_abbrevs[i]=${${(M)${fmri_abbrevs[i]}:#(#b)((#s)|*/)$PREFIX*}#$match[1]}
+		done
+
+		# Remove the "default" instance identifier if we can (not for
+		# svccfg)
+		# TODO Can't remove default when there are other instances.
+		if [[ $type == "-i" ]]; then
+			fmri_abbrevs=( ${fmri_abbrevs//:default(#e)/} )
+		fi
+
+		# Search for a second match within each result.
+		# for m in $fmri_abbrevs; do
+		# 	if [[ -n ${(M)m:#((#s)|*/)$PREFIX*/$PREFIX*} ]]; then
+		# 		fmri_abbrevs=( $fmri_abbrevs ${${(SMI:1:)m%%/$PREFIX*}#/} )
+		# 	fi
+		# done
+
+		# After playing with _multi_parts, I'm not sure it's actually that useful.
+		# _wanted fmri expl "full or unambiguously abbreviated FMRIs" _multi_parts / fmri_abbrevs
+		_wanted fmri expl "full or unambiguously abbreviated FMRIs" compadd $fmri_abbrevs
+		;;
+
+	(-m)
+		_wanted fmri expl "milestone FMRIs" \
+			compadd $(svcs -H -o fmri svc:/milestone/\*) all
+		;;
+
+	(-r)
+		# TODO: need some way to pick out only restarters
+		_wanted fmri expl "restarter FMRIs" compadd master svc:/network/inetd:default
+		;;
+
+	(*)
+		_message "unknown argument to _svcs_fmri: $type"
+		;;
+	esac
+}
+
+_smf_caching_policy() {
+	# /etc/svc/repository.db is not a public interface, so this is kinda
+	# grody.
+	[[ ! -f "$1" || /etc/svc/repository.db -nt "$1" ]]
+}
+
+_svcs_fmri "$@"
diff --git a/Completion/Unix/Command/.distfiles b/Completion/Unix/Command/.distfiles
index 727443a13..654f8a8d8 100644
--- a/Completion/Unix/Command/.distfiles
+++ b/Completion/Unix/Command/.distfiles
@@ -142,6 +142,10 @@ _php
 _pine
 _ping
 _pkg-config
+_pkg_instance
+_pkgadd
+_pkginfo
+_pkgrm
 _pon
 _postfix
 _prcs
@@ -223,5 +227,7 @@ _yodl
 _yp
 _zcat
 _zdump
+_zfs
 _zip
+_zpool
 '
diff --git a/Completion/Unix/Command/_pkg_instance b/Completion/Unix/Command/_pkg_instance
new file mode 100644
index 000000000..3f4c49219
--- /dev/null
+++ b/Completion/Unix/Command/_pkg_instance
@@ -0,0 +1,20 @@
+#autoload
+
+local -A opts
+local whicharg
+
+zparseopts -E -D -- '-_opts:=opts'
+
+whicharg=${opts#*:}
+
+case ${opts%:*} in
+(installed)
+	compadd "$@" - ${opt_args[$whicharg]}/var/sadm/pkg/*/pkginfo(:h:t)
+	;;
+(spooled)
+	compadd "$@" - ${opt_args[$whicharg]}/*(:t)
+	;;
+(uninstalled)
+	compadd "$@" - ${opt_args[$whicharg]:-/var/spool/pkg}/*/pkgmap(:h:t)
+	;;
+esac
diff --git a/Completion/Unix/Command/_pkgadd b/Completion/Unix/Command/_pkgadd
new file mode 100644
index 000000000..042cc79a1
--- /dev/null
+++ b/Completion/Unix/Command/_pkgadd
@@ -0,0 +1,32 @@
+#compdef pkgadd
+
+_pkgadd_pass() {
+	_values -S : 'password descriptor' \
+	'(file env console)pass[Literal password]:password:' \
+	'(pass file console)env[Environment variable]:environment:_parameters -g "*export*"' \
+	'(pass env console)file[File]:file:_files' \
+	'(pass env file)console[From /dev/tty]'
+}
+
+_pkgadd() {
+	_arguments -s \
+	'-d[Device]:device file:_files' \
+	'-x[HTTP(S) proxy]:HTTP proxy: ' \
+	'-k[Keystore]:keystore:_files' \
+	'-P[Password to decrypt keystore]:password:_pkgadd_pass' \
+	'-Y[Select packages by category]:category: ' \
+	- set1 \
+	'-n[Non-interactive mode]' \
+	'-v[Trace all scripts]' \
+	'-a[Admin file]:admin file:_files' \
+	"-M[Don't use vfstab file]" \
+	'-R[Root path]:root path:_files -/' \
+	'-r[Response file]:response file:_files' \
+	'-V[Alternate vfstab file]:vfstab file:_files' \
+	'*:package instance:_pkg_instance --_opts uninstalled:-d' \
+	- set2 \
+	'-s[Spool package]:spool directory:_files -/' \
+	'*:package instance:_pkg_instance --_opts uninstalled:-d'
+}
+
+_pkgadd "$@"
diff --git a/Completion/Unix/Command/_pkginfo b/Completion/Unix/Command/_pkginfo
new file mode 100644
index 000000000..0253ab3e3
--- /dev/null
+++ b/Completion/Unix/Command/_pkginfo
@@ -0,0 +1,22 @@
+#compdef pkginfo
+
+_pkginfo() {
+	_arguments -s \
+	'(-q -r -x)-l[Long listing]' \
+	'(-l -r -x)-q[Quiet mode]' \
+	'(-l -q -x)-r[Relocation base]' \
+	'(-l -q -r)-x[Extracted listing]' \
+	'-c[Category]:category: ' \
+	'-a[Architecture]:architecture: ' \
+	'-v[Version]:version: ' \
+	- set1 \
+	'(-p)-i[Select completely installed packages]' \
+	'(-i)-p[Select partially installed packages]' \
+	'-R[Root path]:root path:_files -/' \
+	'*:package instance:_pkg_instance --_opts installed:set1--R' \
+	- set2 \
+	'-d[Device]:device file:_files' \
+	'*:package instance:_pkg_instance --_opts uninstalled:set2--d'
+}
+
+_pkginfo "$@"
diff --git a/Completion/Unix/Command/_pkgrm b/Completion/Unix/Command/_pkgrm
new file mode 100644
index 000000000..4edccbfda
--- /dev/null
+++ b/Completion/Unix/Command/_pkgrm
@@ -0,0 +1,20 @@
+#compdef pkgrm
+
+_pkgrm() {
+	_arguments -s \
+	'-Y[Select packages by category]:category: ' \
+	- set1 \
+	'-n[Non-interactive mode]' \
+	'-v[Trace all scripts]' \
+	'-a[Admin file]:admin file:_files' \
+	"-A[Force removal of all files]" \
+	"-M[Don't use vfstab file]" \
+	'-R[Root path]:root path:_files -/' \
+	'-V[Alternate vfstab file]:vfstab file:_files' \
+	'*:package instance:_pkg_instance --_opts installed:set1--R' \
+	- set2 \
+	'-s[Spool package]:spool directory:_files -/' \
+	'*:package instance:_pkg_instance --_opts spooled:set2--s'
+}
+
+_pkgrm "$@"
diff --git a/Completion/Unix/Command/_zfs b/Completion/Unix/Command/_zfs
new file mode 100644
index 000000000..21ab5eaa9
--- /dev/null
+++ b/Completion/Unix/Command/_zfs
@@ -0,0 +1,238 @@
+#compdef zfs
+
+_zfs() {
+	local context state line expl
+	typeset -A opt_args
+	local -a subcmds rw_properties rw_propnames ro_properties
+
+	subcmds=(
+		"create" "destroy" "clone" "promote" "rename" "snapshot"
+		"rollback" "list" "set" "get" "inherit" "mount" "unmount"
+		"share" "unshare" "send" "receive" "allow" "unallow"
+		"upgrade"
+	)
+
+	ro_properties=(
+		"name" "type" "creation" "used" "available" "referenced"
+		"compressratio" "mounted" "origin"
+	)
+
+	# TODO: Be cleverer about what values can be set.  Is there any way to
+	# set the sorting for *size properties to false by default?
+	rw_properties=(
+		"aclinherit:value:(discard noallow secure passthrough)"
+		"aclmode:value:(discard groupmask passthrough)"
+		"atime:value:(on off)"
+		"canmount:value:(on off)"
+		"checksum:value:(on off fletcher2 fletcher4 sha256)"
+		"compression:value:(on off lzjb gzip gzip-{1..9})"
+		"copies:value:(1 2 3)"
+		"devices:value:(on off)"
+		"exec:value:(on off)"
+		"mountpoint:value:{if [[ -prefix /* ]]; then _path_files -/; else _wanted mountpoints expl 'mountpoint (type \"/\" to start completing paths)' compadd legacy none; fi}"
+		"quota:number or 'none':{if [[ -prefix [0-9]## ]]; then _message -e 'number'; elif [[ $PREFIX == quota= ]]; then _wanted none expl 'number or none' compadd none; else _wanted none expl 'quota' compadd none; fi}"
+		"readonly:value:(on off)"
+		"recordsize:value:(512 1K 2K 4K 8K 16K 32K 64K 128K)"
+		"reservation:value:" # <size>, "none"
+		"setuid:value:(on off)"
+		"shareiscsi:value:(on off)" # or "type=<type>"
+		"sharenfs:value:(on off)" # or share(1M) options
+		"snapdir:value:(hidden visible)"
+		"version:value:(1 2 current)"
+		"volblocksize:value:(512 1K 2K 4K 8K 16K 32K 64K 128K)"
+		"volsize:value:" # <size>
+		"xattr:value:(on off)"
+		"zoned:value:(on off)"
+	)
+
+	rw_propnames=( ${rw_properties%%:*} )
+
+	if [[ $service == "zfs" ]]; then
+		_arguments -C -A "-*" \
+			'-\?[Help]' \
+			'*::command:->subcmd' && return 0
+
+		if (( CURRENT == 1 )); then
+			_wanted commands expl "zfs subcommand" compadd -a subcmds
+			return
+		fi
+		service="$words[1]"
+		curcontext="${curcontext%:*}=$service:"
+	fi
+
+	case $service in
+	("create")
+		_arguments -A "-*" \
+			'-p[Create parent datasets]' \
+			'-o[Set initial properties]:property:_values -s , "property" $rw_properties' \
+			- set1 \
+			':filesystem:' \
+			- set2 \
+			'-s[Create sparse volume]' \
+			'-b[Set volblocksize]:blocksize:' \
+			'-V[Set size]:size:' \
+			':volume:'
+		;;
+
+	("destroy")
+		_arguments -A "-*" \
+			'-r[Recursively destroy all children]' \
+			'-R[Recursively destroy all dependents]' \
+			'-f[Force unmounts]' \
+			':filesystem/volume/snapshot:_zfs_dataset'
+		;;
+
+	("snapshot")
+		_arguments -A "-*" \
+			'-r[Recursively snapshot all descendant datasets]' \
+			':filesystem/volume:_zfs_dataset -t fs -t vol -S@'
+		;;
+
+	("rollback")
+		_arguments -A "-*" \
+			'-r[Recursively destroy more recent snapshots]' \
+			'-R[Recursively destroy more recent snapshots and clones]' \
+			'-f[Force unmounts]' \
+			':snapshot:_zfs_dataset -t snap'
+		;;
+
+	("clone")
+		_arguments -A "-*" \
+			'-p[Create parent datasets]' \
+			# XXX needs to bail if there are no snapshots
+			':snapshot:_zfs_dataset -t snap' \
+			':filesystem/volume:'
+		;;
+
+	("promote")
+		# XXX complete only cloned filesystems
+		_arguments \
+			':filesystem:_zfs_dataset -t fs' \
+		;;
+
+	("rename")
+		_arguments -A "-*" \
+			- set1 \
+			'-p[Create parent datasets]' \
+			':filesystem/volume/snapshot:_zfs_dataset' \
+			':filesystem/volume/snapshot:' \
+			- set2 \
+			'-r[Recursively rename snapshots of all descendent datasets]' \
+			':snapshot:_zfs_dataset -t snap' \
+			':snapshot:'
+		;;
+
+	("list")
+		_arguments -A "-*" \
+			'-r[Recursively display children]' \
+			'-H[Scripting mode]' \
+			'-o[Properties to list]:property:_values -s , "property" $ro_properties $rw_propnames' \
+			'*-s[Sort key (ascending)]:property:_values "property" $ro_properties $rw_propnames' \
+			'*-S[Sort key (descending)]:property:_values "property" $ro_properties $rw_propnames' \
+			'-t[Dataset types to list]:dataset type:_values -s , "dataset type" filesystem snapshot volume' \
+			'*:filesystem/volume/snapshot:_zfs_dataset'
+		;;
+
+	("set")
+		_arguments \
+			':property:_values -s , "property" $rw_properties' \
+			'*:filesystem/volume:_zfs_dataset -t fs -t vol'
+		;;
+
+	("get")
+		_arguments -A "-*" \
+			"-r[Recursively display children's properties]" \
+			'-H[Scripting mode]' \
+			'-p[Display numbers exactly]' \
+			'-s[Specify sources]:source:_values -s , "source" local default inherited temporary none' \
+			'-o[Specify fields]:field:_values -s , "field" name property value source' \
+			':property:_values -s , "property" $ro_properties $rw_propnames all' \
+			'*:filesystem/volume/snapshot:_zfs_dataset'
+		;;
+
+	("inherit")
+		_arguments -A "-*" \
+			'-r[Recursively inherit property for all children]' \
+			':property:_values -s , "property" $ro_properties $rw_properties' \
+			'*:filesystem/volume:_zfs_dataset -t fs -t vol'
+		;;
+
+	("mount")
+		_arguments -A "-*" \
+			'-o[Mount options]:mount options:_values -s , "option" {,no}{devices,exec,setuid} ro rw' \
+			'-O[Overlay mount]' \
+			'-v[Report mount progress]' \
+			- set1 \
+			':filesystem:_zfs_dataset -t fs' \
+			- set2 \
+			'-a[Mount all available ZFS filesystems]'
+		;;
+
+	("unmount")
+		_arguments -A "-*" \
+			- set1 \
+			'-f[Force unmount]' \
+			':filesystem:_zfs_dataset -t fs -t mtpt' \
+			- set2 \
+			'-a[Unmount all ZFS filesystems]'
+		;;
+
+	("share")
+		_arguments -A "-*" \
+			- set1 \
+			'-a[Share all available ZFS filesystems]' \
+			- set2 \
+			':filesystem:_zfs_dataset -t fs'
+		;;
+
+	("unshare")
+		_arguments -A "-*" \
+			- set1 \
+			'-a[Unshare all shared ZFS filesystems]' \
+			- set2 \
+			'-F[Force unshare]' \
+			':filesystem:_zfs_dataset -t fs -t mtpt'
+		;;
+
+	("send")
+		_arguments -A "-*" \
+			'-i[Generate an incremental stream]:snapshot:_zfs_dataset -t snap' \
+			':snapshot:_zfs_dataset -t snap'
+		;;
+
+	("receive")
+		_arguments -A "-*" \
+			'-v[Verbose]' \
+			'-n[Do not receive the stream]' \
+			'-F[Force a rollback if necessary]' \
+			- set1 \
+			':filesystem/volume/snapshot:_zfs_dataset' \
+			- set2 \
+			'-d[Set path prefix]:filesystem:_zfs_dataset -t fs'
+		;;
+
+	("allow"|"unallow")
+		_message "unimplemented zfs subcommand: $service"
+		;;
+
+	("upgrade")
+		_arguments -A "-*" \
+			- set1 \
+			'-v[Verbose]' \
+			- set2 \
+			'-a[Upgrade all filesystems on all pools]' \
+			'-r[Upgrade descendent filesystems, too]' \
+			'-V[Upgrade to specified version]:version:(1 2)' \
+			- set3 \
+			'-r[Upgrade descendent filesystems, too]' \
+			'-V[Upgrade to specified version]:version:(1 2)' \
+			':filesystem:_zfs_dataset -t fs' \
+		;;
+
+	(*)
+		_message "unknown zfs subcommand: $service"
+		;;
+	esac
+}
+
+_zfs "$@"
diff --git a/Completion/Unix/Command/_zpool b/Completion/Unix/Command/_zpool
new file mode 100644
index 000000000..ae98c2b7f
--- /dev/null
+++ b/Completion/Unix/Command/_zpool
@@ -0,0 +1,201 @@
+#compdef zpool
+
+_zpool() {
+	local -a subcmds fields
+
+	subcmds=(
+		  create destroy add remove list iostat status online
+		  offline clear attach detach replace scrub import export 
+		  upgrade history get set
+	)
+
+	fields=(
+		name\:"Pool name" size\:"Total size" used\:"Space used"
+		available\:"Space available" capacity\:"Space used (percentage)"
+		health\:"Health status"
+	)
+
+	properties=(
+		"bootfs:value:"
+		"autoreplace:value:(on off)"
+		"delegation:value:(on off)"
+	)
+	propnames=( ${properties%%:*} )
+
+	import_properties=(
+		xattr
+		copies
+		shareiscsi
+		canmount
+		share
+		sharenfs
+		userprop
+		mount
+	)
+
+	if [[ $service == "zpool" ]]; then
+		_arguments -C -A "-*" \
+			'-\?[Help]' \
+			'*::command:->subcmd' && return 0
+
+		if (( CURRENT == 1 )); then
+			_wanted commands expl "zpool subcommand" compadd -a subcmds
+			return
+		fi
+		service="$words[1]"
+		curcontext="${curcontext%:*}=$service:"
+	fi
+
+	case $service in
+	(clear)
+		_arguments \
+			':pool name:_zfs_pool' \
+			'*:virtual device:_files'
+		;;
+
+	(create)
+		# TODO: investigate better vdev handling
+		_arguments -A "-*" \
+			'-f[Force use of in-use devices]' \
+			'-n[Display configuration without creating pool]' \
+			'-R[Use alternate root]:alternate root:_files -/' \
+			'-m[Set mountpoint for root dataset]:mountpoint:' \
+			':pool name:' \
+			'*:virtual device:_files'
+		;;
+
+	(destroy)
+		_arguments -A "-*" \
+			'-f[Force active datasets to be unmounted]' \
+			':pool name:_zfs_pool'
+		;;
+
+	(add)
+		_arguments -A "-*" \
+			'-f[Force use of in-use devices]' \
+			'-n[Display configuration without modifying pool]' \
+			':pool name:_zfs_pool' \
+			'*:virtual device:_files'
+		;;
+
+	(list)
+		_arguments \
+			'-H[Scripted mode]' \
+			'-o[Fields to list]:field:_values -s , "field" ${^fields/\:/[}\]' \
+			'::pool name:_zfs_pool'
+		;;
+
+	(iostat)
+		_arguments -A "-*" \
+			'-v[Verbose statistics]' \
+			'*::pool name:_zfs_pool' \
+			'::interval:' \
+			'::count:'
+		;;
+
+	(status)
+		_arguments -A "-*" \
+			'-v[Verbose information]' \
+			'-x[Show only unhealthy pools]' \
+			'*::pool name:_zfs_pool'
+		;;
+
+	(offline)
+		_arguments -A "-*" \
+			'-t[Offline until next reboot]' \
+			':pool name:_zfs_pool' \
+			'*:virtual device:_files'
+		;;
+
+	(online)
+		_arguments \
+			':pool name:_zfs_pool' \
+			'*:virtual device:_files'
+		;;
+
+	(attach)
+		# TODO: first device should choose first from existing.
+		_arguments \
+			'-f[Force attach, even if in use]' \
+			':pool name:_zfs_pool' \
+			':virtual device:_files' \
+			':virtual device:_files'
+		;;
+
+	(detach)
+		_arguments \
+			':pool name:_zfs_pool' \
+			':virtual device:_files'
+		;;
+
+	(replace)
+		_arguments -A "-*" \
+			'-f[Force attach, even if in use]' \
+			':pool name:_zfs_pool' \
+			':virtual device:_files' \
+			'::virtual device:_files'
+		;;
+
+	(scrub)
+		_arguments -A "-*" \
+			'-s[Stop scrubbing]' \
+			'*:pool name:_zfs_pool'
+		;;
+
+	(export)
+		_arguments -A "-*" \
+			'-f[Forcefully unmount all datasets]' \
+			'*:pool name:_zfs_pool'
+		;;
+
+	(import)
+		# TODO: -o should complete options
+		_arguments -A "-*" \
+			'*-d[Search for devices or files in directory]:_files -/' \
+			'-D[Destroyed pools]' \
+			'-f[Force import]' \
+			- set1 \
+			'-o[Mount options]' \
+			'-p[Set property]:property:_values -s , "property" $import_properties' \
+			'-R[Alternate root]:_files -/' \
+			'*:pool name or id:_zfs_pool' \
+			'::new pool name:' \
+			- set2 \
+			'-a[All pools]'
+		;;
+
+	(get)
+		_arguments -A "-*" \
+			':property:_values -s , "property" $propnames all' \
+			'*:pool name:_zfs_pool'
+		;;
+
+	(set)
+		_arguments -A "-*" \
+			':property:_values -s , "property" $properties' \
+			'*:pool name:_zfs_pool'
+		;;
+
+	(upgrade)
+		_arguments -A "-*" \
+			- set1 \
+			'-v[Display ZFS versions and descriptions]' \
+			- set2 \
+			'-a[Upgrade all pools]' \
+			'*:pool name:_zfs_pool'
+		;;
+
+	(history)
+		_arguments -A "-*" \
+			'-i[Display internal events]' \
+			'-l[Long format]' \
+			'*:pool name:_zfs_pool'
+		;;
+
+	(*)
+		_message "unknown zpool subcommand: $service"
+		;;
+	esac
+}
+
+_zpool "$@"
diff --git a/Completion/Unix/Type/.distfiles b/Completion/Unix/Type/.distfiles
index 4801f84c1..ecf086777 100644
--- a/Completion/Unix/Type/.distfiles
+++ b/Completion/Unix/Type/.distfiles
@@ -48,4 +48,6 @@ _urls
 _user_at_host
 _users
 _users_on
+_zfs_dataset
+_zfs_pool
 '
diff --git a/Completion/Unix/Type/_zfs_dataset b/Completion/Unix/Type/_zfs_dataset
new file mode 100644
index 000000000..1840fb413
--- /dev/null
+++ b/Completion/Unix/Type/_zfs_dataset
@@ -0,0 +1,22 @@
+#autoload
+
+local -a type typearg list
+
+zparseopts -D -E -a type t+:
+
+[[ -n $type[(r)fs] ]]   && typearg=( filesystem )
+[[ -n $type[(r)vol] ]]  && typearg=( $typearg volume )
+[[ -n $type[(r)snap] ]] && typearg=( $typearg snapshot )
+[[ -n $typearg ]] && typearg=( -t ${(j:,:)typearg} )
+
+datasetlist=( ${="$(zfs list -H -o name $typearg)":#no datasets available} )
+
+expl_type=${typearg[2,-1]//,/\/}
+if [[ -n $type[(r)mtpt] ]]; then
+	mlist=( ${="$(zfs list -H -o mountpoint $typearg)":#no mountpoints available} )
+	datasetlist=( $datasetlist $mlist )
+	expl_type="$expl_type/mountpoint"
+fi
+
+# compadd "$@" - $list
+_wanted dataset expl "$expl_type" _multi_parts "$@" / datasetlist
diff --git a/Completion/Unix/Type/_zfs_pool b/Completion/Unix/Type/_zfs_pool
new file mode 100644
index 000000000..7db865c7b
--- /dev/null
+++ b/Completion/Unix/Type/_zfs_pool
@@ -0,0 +1,3 @@
+#autoload
+
+compadd "$@" - $(zpool list -H -o name)