mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-01 21:51:40 +02:00
53395: complete snapshot ranges for zfs destroy
This commit is contained in:
parent
f77e469ad6
commit
eb8e217f1b
3 changed files with 33 additions and 5 deletions
|
@ -1,5 +1,9 @@
|
|||
2025-02-28 Oliver Kiddle <opk@zsh.org>
|
||||
|
||||
* 53395: Completion/Unix/Type/_zfs_dataset,
|
||||
Completion/Unix/Command/_zfs:
|
||||
complete snapshot ranges for zfs destroy
|
||||
|
||||
* Ronan Pigott: 53393: Completion/Unix/Command/_python,
|
||||
Completion/Unix/Command/_python_module-http.server,
|
||||
Completion/Unix/Command/_python_module-json.tool,
|
||||
|
|
|
@ -434,7 +434,7 @@ case $service:$words[1] in
|
|||
'-R[recursively destroy all dependents]' \
|
||||
'(-f)-d[delete or mark deferred]' \
|
||||
'(-d)-f[force unmounts]' \
|
||||
':dataset:_zfs_dataset -t fs -t vol ${=${opt_args[(i)-f]:--t snap}:/-f/} ${=${opt_args[(i)-*]:--t bookmark}:/-?/}'
|
||||
':dataset:_zfs_dataset -t fs -t vol ${=${opt_args[(i)-f]:--t snap -t range}:/-f/} ${=${opt_args[(i)-*]:--t bookmark}:/-?/}'
|
||||
;;
|
||||
|
||||
zfs:snap(|shot))
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#autoload
|
||||
|
||||
local -a type expl_type_arr rsrc rdst paths_allowed
|
||||
local -a type expl_type_arr rsrc rdst paths_allowed suf
|
||||
local -a typearg datasetlist expl mlist
|
||||
local expl_type
|
||||
|
||||
|
@ -9,11 +9,16 @@ local expl_type
|
|||
# -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
|
||||
# in addition to the usual types
|
||||
# clone - cloned file systems
|
||||
# mtpt - add mountpoints
|
||||
# range - allow a range of snapshots
|
||||
zparseopts -D -E e:=expl_type_arr p=paths_allowed r1=rsrc r2=rdst t+:=type
|
||||
|
||||
suf=( -r '\n\t\- @\\#' )
|
||||
[[ -n $type[(r)fs] ]] && typearg=( filesystem )
|
||||
[[ -n $type[(r)vol] ]] && typearg+=( volume )
|
||||
[[ -n $type[(r)snap] ]] && typearg+=( snapshot )
|
||||
[[ -n $type[(r)snap] || -prefix *@ ]] && typearg+=( snapshot )
|
||||
[[ -n $type[(r)share] && $implementation = solaris ]] && typearg+=( share )
|
||||
[[ -n $type[(r)bookmark] && $implementation = openzfs ]] &&
|
||||
typearg+=( bookmark )
|
||||
|
@ -62,9 +67,28 @@ fi
|
|||
if [[ -n $type[(r)clone] ]]; then
|
||||
datasetlist=( ${(f)"$(zfs list -H -o name,origin -t filesystem 2>/dev/null | awk -F$'\t' "\$2 != \"-\" {print \$1}")":#no cloned filesystems available} )
|
||||
else
|
||||
[[ -n $type[(r)range] && $implementation = openzfs ]] &&
|
||||
typearg+=( -s creation ) suf=( -S% -r '\n\t\- ,' )
|
||||
datasetlist=( ${(f)"$(zfs list -H -o name $typearg 2>/dev/null)":#no datasets available} )
|
||||
fi
|
||||
|
||||
if [[ -n $type[(r)range] && -prefix *[%,] && $implementation = openzfs ]]; then
|
||||
if [[ -n ${datasetlist[(r)${PREFIX%@*}@*]} ]]; then
|
||||
datasetlist=( ${${(M)datasetlist:#${PREFIX%@*}@*}##*@} )
|
||||
compset -P '*[@,]'
|
||||
# if we can find the starting snapshot filter to later ones
|
||||
[[ -prefix *% ]] && (( ${#datasetlist[(r)${PREFIX%\%*},-1]} > 2 )) &&
|
||||
datasetlist=( ${${datasetlist[(r)${PREFIX%\%*},-1]}[2,-1]} )
|
||||
expl_type=""
|
||||
compset -P '*%' && suf=( -qS, ) expl_type="end "
|
||||
_description snapshots expl "${expl_type}snapshot"
|
||||
compadd $suf "$expl[@]" -a datasetlist
|
||||
else
|
||||
_message -e snapshots 'snapshot'
|
||||
fi
|
||||
return
|
||||
fi
|
||||
|
||||
expl_type=${typearg[2,-1]//,/\/}
|
||||
if [[ -n $type[(r)mtpt] ]]; then
|
||||
mlist=( ${(f)"$(zfs list -H -o mountpoint $typearg 2>/dev/null)":#no mountpoints available} )
|
||||
|
@ -77,4 +101,4 @@ if [[ -n $expl_type_arr[2] ]]; then
|
|||
fi
|
||||
|
||||
_description datasets expl "$expl_type"
|
||||
_multi_parts "$@" "$expl[@]" -q / datasetlist
|
||||
_multi_parts $suf "$@" "$expl[@]" -q / datasetlist
|
||||
|
|
Loading…
Reference in a new issue