summary refs log tree commit diff
path: root/Completion/Unix
diff options
context:
space:
mode:
Diffstat (limited to 'Completion/Unix')
-rw-r--r--Completion/Unix/Command/_zfs27
-rw-r--r--Completion/Unix/Command/_zpool3
-rw-r--r--Completion/Unix/Type/_zfs_dataset54
3 files changed, 61 insertions, 23 deletions
diff --git a/Completion/Unix/Command/_zfs b/Completion/Unix/Command/_zfs
index 204784d56..4cc24a59f 100644
--- a/Completion/Unix/Command/_zfs
+++ b/Completion/Unix/Command/_zfs
@@ -1,5 +1,5 @@
 #compdef zfs
-# Synced with the S11U1 build 16 man page
+# Synced with the S11U1 build 20 man page
 
 _zfs() {
 	local context state line expl
@@ -21,7 +21,7 @@ _zfs() {
 		"compressratio" "mounted" "origin" "usedbychildren"
 		"usedbydataset" "usedbyrefreservation" "usedbysnapshots"
 		"defer_destroy" "userused@" "userrefs" "groupused@"
-		"keystatus" "rekeydate"
+		"keychangedate" "keystatus" "rekeydate"
 	)
 
 	# TODO: Be cleverer about what values can be set.  Is there any way to
@@ -111,12 +111,12 @@ _zfs() {
 			'-p[Create parent datasets]' \
 			'-o[Set initial properties]:property:_values -s , "property" $create_properties' \
 			- set1 \
-			':filesystem:' \
+			':filesystem:_zfs_dataset -t fs -e "parent dataset"' \
 			- set2 \
 			'-s[Create sparse volume]' \
 			'-b[Set volblocksize]:blocksize:' \
 			'-V[Set size]:size:' \
-			':volume:'
+			':volume:_zfs_dataset -t fs -e "parent dataset"'
 		;;
 
 	("destroy")
@@ -153,25 +153,20 @@ _zfs() {
 			'-K[Create encryption key]' \
 			'-o[Set property]:property:_values -s , "property" $create_properties' \
 			':snapshot:_zfs_dataset -t snap' \
-			':filesystem/volume:'
+			':filesystem/volume:_zfs_dataset -t fs -e "parent dataset"'
 		;;
 
 	("promote")
-		# XXX complete only cloned filesystems
 		_arguments \
-			':filesystem:_zfs_dataset -t fs' \
+			':filesystem:_zfs_dataset -t clone' \
 		;;
 
 	("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:'
+			'(-r)-p[Create parent datasets]' \
+			'(-p)-r[Recursively rename snapshots of all descendent datasets]' \
+			':dataset:_zfs_dataset -r1' \
+			':dataset:_zfs_dataset -r2'
 		;;
 
 	("list")
@@ -182,7 +177,7 @@ _zfs() {
 			'-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' \
+			'-t[Dataset types to list]:dataset type:_values -s , "dataset type" all filesystem snapshot volume' \
 			'*:filesystem/volume/snapshot/path:_zfs_dataset -p'
 		;;
 
diff --git a/Completion/Unix/Command/_zpool b/Completion/Unix/Command/_zpool
index 568f493d0..0af2ab32d 100644
--- a/Completion/Unix/Command/_zpool
+++ b/Completion/Unix/Command/_zpool
@@ -1,5 +1,5 @@
 #compdef zpool
-# Synced with the S11U1 build 16 man page
+# Synced with the S11U1 build 19 man page
 
 _zpool() {
 	local context state line expl
@@ -108,6 +108,7 @@ _zpool() {
 	(create)
 		# TODO: investigate better vdev handling
 		_arguments -A "-*" \
+			'-B[Create EFI boot partition on whole disks]' \
 			'-o[Set pool property at creation time]:property:_values -s , "property" $rw_props' \
 			'-O[Set dataset property at creation time]:property:_values -s , "property" $create_properties_dataset' \
 			'-f[Force use of in-use devices]' \
diff --git a/Completion/Unix/Type/_zfs_dataset b/Completion/Unix/Type/_zfs_dataset
index 1cd49aebf..d862011ac 100644
--- a/Completion/Unix/Type/_zfs_dataset
+++ b/Completion/Unix/Type/_zfs_dataset
@@ -1,13 +1,19 @@
 #autoload
 
-local -a type paths_allowed typearg datasetlist expl
+local -a type expl_type_arr rsrc rdst paths_allowed
+local -a typearg datasetlist expl mlist
 local expl_type
 
-zparseopts -D -E t+:=type p=paths_allowed
+# -e takes an argument which is passed as as the "descr" argument to _wanted
+# -p indicates that filesystem paths, not just dataset names, are allowed
+# -r1 indicates that we're completing the source of a rename
+# -r2 indicates that we're completing the destination of a rename
+# -t takes arguments (what kinds of datasets) and can appear multiple times
+zparseopts -D -E e:=expl_type_arr p=paths_allowed r1=rsrc r2=rdst t+:=type
 
-[[ -n $type[(r)fs] ]]   && typearg=( filesystem )
-[[ -n $type[(r)vol] ]]  && typearg=( $typearg volume )
-[[ -n $type[(r)snap] ]] && typearg=( $typearg snapshot )
+[[ -n $type[(r)fs] ]]    && typearg=( filesystem )
+[[ -n $type[(r)vol] ]]   && typearg=( $typearg volume )
+[[ -n $type[(r)snap] ]]  && typearg=( $typearg snapshot )
 if [[ -n $typearg ]]; then
 	typearg=( -t ${(j:,:)typearg} )
 # We know we're in zfs list if paths_allowed is non-empty.
@@ -20,7 +26,39 @@ if [[ ${#paths_allowed} -gt 0 && $PREFIX == /* ]]; then
 	return
 fi
 
-datasetlist=( ${="$(zfs list -H -o name $typearg)":#no datasets available} )
+if [[ ${#rsrc} -gt 0 ]]; then
+	# With the -r option to zfs rename, we can only rename snapshots.  With the
+	# -p option, we can only rename filesystems and volumes.
+	if [[ -n $words[(r)-r] ]]; then
+		typearg=( -t snapshot )
+	elif [[ -n $words[(r)-p] ]]; then
+		typearg=( -t filesystem,volume )
+	else
+		typearg=( -t filesystem,snapshot,volume )
+	fi
+fi
+
+if [[ ${#rdst} -gt 0 ]]; then
+	if [[ ${words[CURRENT - 1]} == *@* ]]; then
+		# If we're renaming snapshots, there's nothing to complete, so
+		# we simply give instructions.  (In non-recursive cases, we
+		# could put the name of the snapshotted dataset first, but why
+		# bother with the long form?)
+		_message -e 'snapshot name (beginning with "@")'
+		return
+	else
+		# The parent dataset must be a filesystem, and can't rename
+		# a dataset into another pool.  Plus we hardcode the expl.
+		typearg=( -t fs -r ${${words[CURRENT - 1]}%%/*} )
+		expl_type_arr=( -e "parent dataset" )
+	fi
+fi
+
+if [[ -n $type[(r)clone] ]]; then
+	datasetlist=( ${="$(zfs list -H -o name,origin -t fs | awk "\$2 != \"-\" {print \$1}")":#no cloned filesystems available} )
+else
+	datasetlist=( ${="$(zfs list -H -o name $typearg)":#no datasets available} )
+fi
 
 expl_type=${typearg[2,-1]//,/\/}
 if [[ -n $type[(r)mtpt] ]]; then
@@ -29,4 +67,8 @@ if [[ -n $type[(r)mtpt] ]]; then
 	expl_type="$expl_type/mountpoint"
 fi
 
+if [[ -n $expl_type_arr[2] ]]; then
+	expl_type=$expl_type_arr[2]
+fi
+
 _wanted dataset expl "$expl_type" _multi_parts "$@" -q / datasetlist