2020-06-16 22:27:23 +03:00
|
|
|
# Copyright (c) 2010-2016, Aneurin Price <aneurin.price@gmail.com>
|
2014-07-19 03:45:49 +04:00
|
|
|
|
|
|
|
# Permission is hereby granted, free of charge, to any person
|
|
|
|
# obtaining a copy of this software and associated documentation
|
|
|
|
# files (the "Software"), to deal in the Software without
|
|
|
|
# restriction, including without limitation the rights to use,
|
|
|
|
# copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
# copies of the Software, and to permit persons to whom the
|
|
|
|
# Software is furnished to do so, subject to the following
|
|
|
|
# conditions:
|
|
|
|
|
|
|
|
# The above copyright notice and this permission notice shall be
|
|
|
|
# included in all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
|
|
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
|
|
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
|
|
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
# OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
2021-04-03 02:34:58 +03:00
|
|
|
__ZFS_CMD="@sbindir@/zfs"
|
|
|
|
__ZPOOL_CMD="@sbindir@/zpool"
|
2014-07-19 03:45:49 +04:00
|
|
|
|
2020-06-16 22:27:23 +03:00
|
|
|
# Disable bash's built-in hostname completion, as this makes it impossible to
|
|
|
|
# provide completions containing an @-sign, which is necessary for completing
|
|
|
|
# snapshot names. If bash_completion is in use, this will already be disabled
|
|
|
|
# and replaced with better completions anyway.
|
|
|
|
shopt -u hostcomplete
|
|
|
|
|
2014-07-19 03:45:49 +04:00
|
|
|
__zfs_get_commands()
|
|
|
|
{
|
|
|
|
$__ZFS_CMD 2>&1 | awk '/^\t[a-z]/ {print $1}' | cut -f1 -d '|' | uniq
|
|
|
|
}
|
|
|
|
|
|
|
|
__zfs_get_properties()
|
|
|
|
{
|
|
|
|
$__ZFS_CMD get 2>&1 | awk '$2 == "YES" || $2 == "NO" {print $1}'; echo all name space
|
|
|
|
}
|
|
|
|
|
|
|
|
__zfs_get_editable_properties()
|
|
|
|
{
|
|
|
|
$__ZFS_CMD get 2>&1 | awk '$2 == "YES" {print $1"="}'
|
|
|
|
}
|
|
|
|
|
|
|
|
__zfs_get_inheritable_properties()
|
|
|
|
{
|
|
|
|
$__ZFS_CMD get 2>&1 | awk '$3 == "YES" {print $1}'
|
|
|
|
}
|
|
|
|
|
|
|
|
__zfs_list_datasets()
|
|
|
|
{
|
2020-06-16 22:27:23 +03:00
|
|
|
$__ZFS_CMD list -H -o name -s name -t filesystem,volume "$@"
|
2014-07-19 03:45:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
__zfs_list_filesystems()
|
|
|
|
{
|
2020-06-16 22:27:23 +03:00
|
|
|
$__ZFS_CMD list -H -o name -s name -t filesystem
|
2014-07-19 03:45:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
__zfs_match_snapshot()
|
|
|
|
{
|
2021-05-16 22:59:56 +03:00
|
|
|
local base_dataset="${cur%@*}"
|
|
|
|
if [ "$base_dataset" != "$cur" ]
|
2014-07-19 03:45:49 +04:00
|
|
|
then
|
2021-05-16 22:59:56 +03:00
|
|
|
$__ZFS_CMD list -H -o name -s name -t snapshot -d 1 "$base_dataset"
|
2014-07-19 03:45:49 +04:00
|
|
|
else
|
2021-05-16 22:59:56 +03:00
|
|
|
if [ "$cur" != "" ] && __zfs_list_datasets "$cur" &> /dev/null
|
2020-06-16 22:27:23 +03:00
|
|
|
then
|
2021-05-16 22:59:56 +03:00
|
|
|
$__ZFS_CMD list -H -o name -s name -t filesystem -r "$cur" | tail -n +2
|
2020-06-16 22:27:23 +03:00
|
|
|
# We output the base dataset name even though we might be
|
|
|
|
# completing a command that can only take a snapshot, because it
|
|
|
|
# prevents bash from considering the completion finished when it
|
|
|
|
# ends in the bare @.
|
2021-05-16 22:59:56 +03:00
|
|
|
echo "$cur"
|
|
|
|
echo "$cur@"
|
2020-06-16 22:27:23 +03:00
|
|
|
else
|
2021-05-16 22:59:56 +03:00
|
|
|
local datasets
|
|
|
|
datasets="$(__zfs_list_datasets)"
|
2020-06-16 22:27:23 +03:00
|
|
|
# As above
|
2021-05-16 22:59:56 +03:00
|
|
|
echo "$datasets"
|
2020-06-16 22:27:23 +03:00
|
|
|
if [[ "$cur" == */ ]]
|
|
|
|
then
|
|
|
|
# If the current command ends with a slash, then the only way
|
|
|
|
# it can be completed with a single tab press (ie. in this pass)
|
|
|
|
# is if it has exactly one child, so that's the only time we
|
|
|
|
# need to offer a suggestion with an @ appended.
|
|
|
|
local num_children
|
|
|
|
# This is actually off by one as zfs list includes the named
|
|
|
|
# dataset in addition to its children
|
2021-05-16 22:59:56 +03:00
|
|
|
num_children=$(__zfs_list_datasets -d 1 "${cur%/}" 2> /dev/null | wc -l)
|
2020-06-16 22:27:23 +03:00
|
|
|
if [[ $num_children != 2 ]]
|
|
|
|
then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
fi
|
2021-05-16 22:59:56 +03:00
|
|
|
echo "$datasets" | awk '{print $1 "@"}'
|
2020-06-16 22:27:23 +03:00
|
|
|
fi
|
2014-07-19 03:45:49 +04:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-06-16 22:27:23 +03:00
|
|
|
__zfs_match_snapshot_or_bookmark()
|
2014-07-19 03:45:49 +04:00
|
|
|
{
|
2021-05-16 22:59:56 +03:00
|
|
|
local base_dataset="${cur%[#@]*}"
|
|
|
|
if [ "$base_dataset" != "$cur" ]
|
2014-07-19 03:45:49 +04:00
|
|
|
then
|
2020-06-16 22:27:23 +03:00
|
|
|
if [[ $cur == *@* ]]
|
|
|
|
then
|
2021-05-16 22:59:56 +03:00
|
|
|
$__ZFS_CMD list -H -o name -s name -t snapshot -d 1 "$base_dataset"
|
2020-06-16 22:27:23 +03:00
|
|
|
else
|
2021-05-16 22:59:56 +03:00
|
|
|
$__ZFS_CMD list -H -o name -s name -t bookmark -d 1 "$base_dataset"
|
2020-06-16 22:27:23 +03:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
$__ZFS_CMD list -H -o name -s name -t filesystem,volume
|
2021-05-16 22:59:56 +03:00
|
|
|
if [ -e "$cur" ] && $__ZFS_CMD list -H -o name -s name -t filesystem,volume "$cur" &> /dev/null
|
2020-06-16 22:27:23 +03:00
|
|
|
then
|
2021-05-16 22:59:56 +03:00
|
|
|
echo "$cur@"
|
|
|
|
echo "$cur#"
|
2020-06-16 22:27:23 +03:00
|
|
|
fi
|
2014-07-19 03:45:49 +04:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
__zfs_match_multiple_snapshots()
|
|
|
|
{
|
2021-05-16 22:59:56 +03:00
|
|
|
local existing_opts
|
|
|
|
existing_opts="$(expr "$cur" : '\(.*\)[%,]')"
|
|
|
|
if [ -e "$existing_opts" ]
|
2014-07-19 03:45:49 +04:00
|
|
|
then
|
2021-05-16 22:59:56 +03:00
|
|
|
local base_dataset="${cur%@*}"
|
|
|
|
if [ "$base_dataset" != "$cur" ]
|
2014-07-19 03:45:49 +04:00
|
|
|
then
|
2021-05-16 22:59:56 +03:00
|
|
|
local cur="${cur##*,}"
|
2014-07-19 03:45:49 +04:00
|
|
|
if [[ $cur =~ ^%|%.*% ]]
|
|
|
|
then
|
|
|
|
# correct range syntax is start%end
|
|
|
|
return 1
|
|
|
|
fi
|
2021-05-16 22:59:56 +03:00
|
|
|
local range_start
|
|
|
|
range_start="$(expr "$cur" : '\(.*%\)')"
|
2021-05-22 00:43:38 +03:00
|
|
|
# shellcheck disable=SC2016
|
2021-05-16 22:59:56 +03:00
|
|
|
$__ZFS_CMD list -H -o name -s name -t snapshot -d 1 "$base_dataset" | sed 's$.*@$'"$range_start"'$g'
|
2014-07-19 03:45:49 +04:00
|
|
|
fi
|
|
|
|
else
|
2020-06-16 22:27:23 +03:00
|
|
|
__zfs_match_snapshot_or_bookmark
|
2014-07-19 03:45:49 +04:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
__zfs_list_volumes()
|
|
|
|
{
|
2020-06-16 22:27:23 +03:00
|
|
|
$__ZFS_CMD list -H -o name -s name -t volume
|
2014-07-19 03:45:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
__zfs_argument_chosen()
|
|
|
|
{
|
|
|
|
local word property
|
|
|
|
for word in $(seq $((COMP_CWORD-1)) -1 2)
|
|
|
|
do
|
|
|
|
local prev="${COMP_WORDS[$word]}"
|
|
|
|
if [[ ${COMP_WORDS[$word-1]} != -[tos] ]]
|
|
|
|
then
|
2020-06-16 22:27:23 +03:00
|
|
|
if [[ "$prev" == [^,]*,* ]] || [[ "$prev" == *[@:\#]* ]]
|
2014-07-19 03:45:49 +04:00
|
|
|
then
|
|
|
|
return 0
|
|
|
|
fi
|
2021-05-22 00:43:38 +03:00
|
|
|
for property in "$@"
|
2014-07-19 03:45:49 +04:00
|
|
|
do
|
2020-06-16 22:27:23 +03:00
|
|
|
if [[ $prev == "$property"* ]]
|
2014-07-19 03:45:49 +04:00
|
|
|
then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
__zfs_complete_ordered_arguments()
|
|
|
|
{
|
|
|
|
local list1=$1
|
|
|
|
local list2=$2
|
|
|
|
local cur=$3
|
|
|
|
local extra=$4
|
2021-05-22 00:43:38 +03:00
|
|
|
# shellcheck disable=SC2086
|
2014-07-19 03:45:49 +04:00
|
|
|
if __zfs_argument_chosen $list1
|
|
|
|
then
|
2021-11-30 21:23:10 +03:00
|
|
|
mapfile -t COMPREPLY < <(compgen -W "$list2 $extra" -- "$cur")
|
2014-07-19 03:45:49 +04:00
|
|
|
else
|
2021-11-30 21:23:10 +03:00
|
|
|
mapfile -t COMPREPLY < <(compgen -W "$list1 $extra" -- "$cur")
|
2014-07-19 03:45:49 +04:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
__zfs_complete_multiple_options()
|
|
|
|
{
|
|
|
|
local options=$1
|
|
|
|
local cur=$2
|
2021-05-22 00:43:38 +03:00
|
|
|
local existing_opts
|
2014-07-19 03:45:49 +04:00
|
|
|
|
2021-11-30 21:23:10 +03:00
|
|
|
mapfile -t COMPREPLY < <(compgen -W "$options" -- "${cur##*,}")
|
2021-05-22 00:43:38 +03:00
|
|
|
existing_opts=$(expr "$cur" : '\(.*,\)')
|
2021-11-30 21:23:10 +03:00
|
|
|
if [ -n "$existing_opts" ]
|
2014-07-19 03:45:49 +04:00
|
|
|
then
|
|
|
|
COMPREPLY=( "${COMPREPLY[@]/#/${existing_opts}}" )
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
__zfs_complete_switch()
|
|
|
|
{
|
|
|
|
local options=$1
|
|
|
|
if [[ ${cur:0:1} == - ]]
|
|
|
|
then
|
2021-11-30 21:23:10 +03:00
|
|
|
mapfile -t COMPREPLY < <(compgen -W "-{$options}" -- "$cur")
|
2014-07-19 03:45:49 +04:00
|
|
|
return 0
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-06-16 22:27:23 +03:00
|
|
|
__zfs_complete_nospace()
|
|
|
|
{
|
|
|
|
# Google indicates that there may still be bash versions out there that
|
|
|
|
# don't have compopt.
|
|
|
|
if type compopt &> /dev/null
|
|
|
|
then
|
|
|
|
compopt -o nospace
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2014-07-19 03:45:49 +04:00
|
|
|
__zfs_complete()
|
|
|
|
{
|
|
|
|
local cur prev cmd cmds
|
|
|
|
COMPREPLY=()
|
2020-06-16 22:27:23 +03:00
|
|
|
if type _get_comp_words_by_ref &> /dev/null
|
|
|
|
then
|
|
|
|
# Don't split on colon
|
|
|
|
_get_comp_words_by_ref -n : -c cur -p prev -w COMP_WORDS -i COMP_CWORD
|
|
|
|
else
|
|
|
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
|
|
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
|
|
|
fi
|
2014-07-19 03:45:49 +04:00
|
|
|
cmd="${COMP_WORDS[1]}"
|
|
|
|
|
|
|
|
if [[ ${prev##*/} == zfs ]]
|
|
|
|
then
|
|
|
|
cmds=$(__zfs_get_commands)
|
2021-11-30 21:23:10 +03:00
|
|
|
mapfile -t COMPREPLY < <(compgen -W "$cmds -?" -- "$cur")
|
2014-07-19 03:45:49 +04:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
case "${cmd}" in
|
2020-06-16 22:27:23 +03:00
|
|
|
bookmark)
|
|
|
|
if __zfs_argument_chosen
|
|
|
|
then
|
2021-11-30 21:23:10 +03:00
|
|
|
mapfile -t COMPREPLY < <(compgen -W "${prev%@*}# ${prev/@/#}" -- "$cur")
|
2020-06-16 22:27:23 +03:00
|
|
|
else
|
2021-11-30 21:23:10 +03:00
|
|
|
mapfile -t COMPREPLY < <(compgen -W "$(__zfs_match_snapshot)" -- "$cur")
|
2020-06-16 22:27:23 +03:00
|
|
|
fi
|
|
|
|
;;
|
2014-07-19 03:45:49 +04:00
|
|
|
clone)
|
|
|
|
case "${prev}" in
|
|
|
|
-o)
|
2021-11-30 21:23:10 +03:00
|
|
|
mapfile -t COMPREPLY < <(compgen -W "$(__zfs_get_editable_properties)" -- "$cur")
|
2020-06-16 22:27:23 +03:00
|
|
|
__zfs_complete_nospace
|
2014-07-19 03:45:49 +04:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
if ! __zfs_complete_switch "o,p"
|
|
|
|
then
|
|
|
|
if __zfs_argument_chosen
|
|
|
|
then
|
2021-11-30 21:23:10 +03:00
|
|
|
mapfile -t COMPREPLY < <(compgen -W "$(__zfs_list_datasets)" -- "$cur")
|
2014-07-19 03:45:49 +04:00
|
|
|
else
|
2021-11-30 21:23:10 +03:00
|
|
|
mapfile -t COMPREPLY < <(compgen -W "$(__zfs_match_snapshot)" -- "$cur")
|
2014-07-19 03:45:49 +04:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
get)
|
|
|
|
case "${prev}" in
|
|
|
|
-d)
|
2021-11-30 21:23:10 +03:00
|
|
|
mapfile -t COMPREPLY < <(compgen -W "" -- "$cur")
|
2014-07-19 03:45:49 +04:00
|
|
|
;;
|
|
|
|
-t)
|
bash_completion: add missing attributes
There a some attributes missing which are shown in man pages:
zfs list -t type
A comma-separated list of types to display, where type is one of filesystem, snapshot, volume, *bookmark*, or all. For example, specifying -t snapshot displays only snapshots.
zfs get -s source
A comma-separated list of sources to display. Those properties coming from a source other than those in this list are ignored. Each source must be one of the following: local, default, inherited, temporary, *received*, and none. The default value is all sources.
zfs get -t type
A comma-separated list of types to display, where type is one of filesystem, snapshot, volume, bookmark, or all.
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Grischa Zengel <github.zfsonlinux@zengel.info>
Closes #10418
2020-06-11 03:51:15 +03:00
|
|
|
__zfs_complete_multiple_options "filesystem volume snapshot bookmark all" "$cur"
|
2014-07-19 03:45:49 +04:00
|
|
|
;;
|
|
|
|
-s)
|
bash_completion: add missing attributes
There a some attributes missing which are shown in man pages:
zfs list -t type
A comma-separated list of types to display, where type is one of filesystem, snapshot, volume, *bookmark*, or all. For example, specifying -t snapshot displays only snapshots.
zfs get -s source
A comma-separated list of sources to display. Those properties coming from a source other than those in this list are ignored. Each source must be one of the following: local, default, inherited, temporary, *received*, and none. The default value is all sources.
zfs get -t type
A comma-separated list of types to display, where type is one of filesystem, snapshot, volume, bookmark, or all.
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Grischa Zengel <github.zfsonlinux@zengel.info>
Closes #10418
2020-06-11 03:51:15 +03:00
|
|
|
__zfs_complete_multiple_options "local default inherited temporary received none" "$cur"
|
2014-07-19 03:45:49 +04:00
|
|
|
;;
|
|
|
|
-o)
|
|
|
|
__zfs_complete_multiple_options "name property value source received all" "$cur"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
if ! __zfs_complete_switch "H,r,p,d,o,t,s"
|
|
|
|
then
|
2021-05-22 00:43:38 +03:00
|
|
|
# shellcheck disable=SC2046
|
2014-07-19 03:45:49 +04:00
|
|
|
if __zfs_argument_chosen $(__zfs_get_properties)
|
|
|
|
then
|
2021-11-30 21:23:10 +03:00
|
|
|
mapfile -t COMPREPLY < <(compgen -W "$(__zfs_match_snapshot)" -- "$cur")
|
2014-07-19 03:45:49 +04:00
|
|
|
else
|
|
|
|
__zfs_complete_multiple_options "$(__zfs_get_properties)" "$cur"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
inherit)
|
|
|
|
if ! __zfs_complete_switch "r"
|
|
|
|
then
|
2021-05-22 00:43:38 +03:00
|
|
|
__zfs_complete_ordered_arguments "$(__zfs_get_inheritable_properties)" "$(__zfs_match_snapshot)" "$cur"
|
2014-07-19 03:45:49 +04:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
list)
|
|
|
|
case "${prev}" in
|
|
|
|
-d)
|
2021-11-30 21:23:10 +03:00
|
|
|
mapfile -t COMPREPLY < <(compgen -W "" -- "$cur")
|
2014-07-19 03:45:49 +04:00
|
|
|
;;
|
|
|
|
-t)
|
bash_completion: add missing attributes
There a some attributes missing which are shown in man pages:
zfs list -t type
A comma-separated list of types to display, where type is one of filesystem, snapshot, volume, *bookmark*, or all. For example, specifying -t snapshot displays only snapshots.
zfs get -s source
A comma-separated list of sources to display. Those properties coming from a source other than those in this list are ignored. Each source must be one of the following: local, default, inherited, temporary, *received*, and none. The default value is all sources.
zfs get -t type
A comma-separated list of types to display, where type is one of filesystem, snapshot, volume, bookmark, or all.
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Grischa Zengel <github.zfsonlinux@zengel.info>
Closes #10418
2020-06-11 03:51:15 +03:00
|
|
|
__zfs_complete_multiple_options "filesystem volume snapshot bookmark all" "$cur"
|
2014-07-19 03:45:49 +04:00
|
|
|
;;
|
|
|
|
-o)
|
|
|
|
__zfs_complete_multiple_options "$(__zfs_get_properties)" "$cur"
|
|
|
|
;;
|
|
|
|
-s|-S)
|
2021-11-30 21:23:10 +03:00
|
|
|
mapfile -t COMPREPLY < <(compgen -W "$(__zfs_get_properties)" -- "$cur")
|
2014-07-19 03:45:49 +04:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
if ! __zfs_complete_switch "H,r,d,o,t,s,S"
|
|
|
|
then
|
2021-11-30 21:23:10 +03:00
|
|
|
mapfile -t COMPREPLY < <(compgen -W "$(__zfs_match_snapshot)" -- "$cur")
|
2014-07-19 03:45:49 +04:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
promote)
|
2021-11-30 21:23:10 +03:00
|
|
|
mapfile -t COMPREPLY < <(compgen -W "$(__zfs_list_filesystems)" -- "$cur")
|
2014-07-19 03:45:49 +04:00
|
|
|
;;
|
|
|
|
rollback)
|
|
|
|
if ! __zfs_complete_switch "r,R,f"
|
|
|
|
then
|
2021-11-30 21:23:10 +03:00
|
|
|
mapfile -t COMPREPLY < <(compgen -W "$(__zfs_match_snapshot)" -- "$cur")
|
2014-07-19 03:45:49 +04:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
send)
|
2020-06-16 22:27:23 +03:00
|
|
|
if ! __zfs_complete_switch "D,n,P,p,R,v,e,L,i,I"
|
2014-07-19 03:45:49 +04:00
|
|
|
then
|
2020-06-16 22:27:23 +03:00
|
|
|
if __zfs_argument_chosen
|
|
|
|
then
|
2021-11-30 21:23:10 +03:00
|
|
|
mapfile -t COMPREPLY < <(compgen -W "$(__zfs_match_snapshot)" -- "$cur")
|
2020-06-16 22:27:23 +03:00
|
|
|
else
|
|
|
|
if [[ $prev == -*i* ]]
|
|
|
|
then
|
2021-11-30 21:23:10 +03:00
|
|
|
mapfile -t COMPREPLY < <(compgen -W "$(__zfs_match_snapshot_or_bookmark)" -- "$cur")
|
2020-06-16 22:27:23 +03:00
|
|
|
else
|
2021-11-30 21:23:10 +03:00
|
|
|
mapfile -t COMPREPLY < <(compgen -W "$(__zfs_match_snapshot)" -- "$cur")
|
2020-06-16 22:27:23 +03:00
|
|
|
fi
|
|
|
|
fi
|
2014-07-19 03:45:49 +04:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
snapshot)
|
|
|
|
case "${prev}" in
|
|
|
|
-o)
|
2021-11-30 21:23:10 +03:00
|
|
|
mapfile -t COMPREPLY < <(compgen -W "$(__zfs_get_editable_properties)" -- "$cur")
|
2020-06-16 22:27:23 +03:00
|
|
|
__zfs_complete_nospace
|
2014-07-19 03:45:49 +04:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
if ! __zfs_complete_switch "o,r"
|
|
|
|
then
|
2021-11-30 21:23:10 +03:00
|
|
|
mapfile -t COMPREPLY < <(compgen -W "$(__zfs_match_snapshot)" -- "$cur")
|
2020-06-16 22:27:23 +03:00
|
|
|
__zfs_complete_nospace
|
2014-07-19 03:45:49 +04:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
set)
|
2021-05-22 00:43:38 +03:00
|
|
|
__zfs_complete_ordered_arguments "$(__zfs_get_editable_properties)" "$(__zfs_match_snapshot)" "$cur"
|
2020-06-16 22:27:23 +03:00
|
|
|
__zfs_complete_nospace
|
2014-07-19 03:45:49 +04:00
|
|
|
;;
|
|
|
|
upgrade)
|
|
|
|
case "${prev}" in
|
|
|
|
-a|-V|-v)
|
2021-11-30 21:23:10 +03:00
|
|
|
mapfile -t COMPREPLY < <(compgen -W "" -- "$cur")
|
2014-07-19 03:45:49 +04:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
if ! __zfs_complete_switch "a,V,v,r"
|
|
|
|
then
|
2021-11-30 21:23:10 +03:00
|
|
|
mapfile -t COMPREPLY < <(compgen -W "$(__zfs_list_filesystems)" -- "$cur")
|
2014-07-19 03:45:49 +04:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
destroy)
|
|
|
|
if ! __zfs_complete_switch "d,f,n,p,R,r,v"
|
|
|
|
then
|
2021-05-22 00:43:38 +03:00
|
|
|
__zfs_complete_multiple_options "$(__zfs_match_multiple_snapshots)" "$cur"
|
2020-06-16 22:27:23 +03:00
|
|
|
__zfs_complete_nospace
|
2014-07-19 03:45:49 +04:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*)
|
2021-11-30 21:23:10 +03:00
|
|
|
mapfile -t COMPREPLY < <(compgen -W "$(__zfs_match_snapshot)" -- "$cur")
|
2014-07-19 03:45:49 +04:00
|
|
|
;;
|
|
|
|
esac
|
2020-06-16 22:27:23 +03:00
|
|
|
if type __ltrim_colon_completions &> /dev/null
|
|
|
|
then
|
|
|
|
__ltrim_colon_completions "$cur"
|
|
|
|
fi
|
2014-07-19 03:45:49 +04:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
__zpool_get_commands()
|
|
|
|
{
|
|
|
|
$__ZPOOL_CMD 2>&1 | awk '/^\t[a-z]/ {print $1}' | uniq
|
|
|
|
}
|
|
|
|
|
|
|
|
__zpool_get_properties()
|
|
|
|
{
|
|
|
|
$__ZPOOL_CMD get 2>&1 | awk '$2 == "YES" || $2 == "NO" {print $1}'; echo all
|
|
|
|
}
|
|
|
|
|
|
|
|
__zpool_get_editable_properties()
|
|
|
|
{
|
|
|
|
$__ZPOOL_CMD get 2>&1 | awk '$2 == "YES" {print $1"="}'
|
|
|
|
}
|
|
|
|
|
|
|
|
__zpool_list_pools()
|
|
|
|
{
|
|
|
|
$__ZPOOL_CMD list -H -o name
|
|
|
|
}
|
|
|
|
|
|
|
|
__zpool_complete()
|
|
|
|
{
|
2021-05-22 00:43:38 +03:00
|
|
|
local cur prev cmd cmds pools
|
2014-07-19 03:45:49 +04:00
|
|
|
COMPREPLY=()
|
|
|
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
|
|
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
|
|
|
cmd="${COMP_WORDS[1]}"
|
|
|
|
|
|
|
|
if [[ ${prev##*/} == zpool ]]
|
|
|
|
then
|
|
|
|
cmds=$(__zpool_get_commands)
|
2021-11-30 21:23:10 +03:00
|
|
|
mapfile -t COMPREPLY < <(compgen -W "$cmds" -- "$cur")
|
2014-07-19 03:45:49 +04:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
case "${cmd}" in
|
|
|
|
get)
|
2021-05-22 00:43:38 +03:00
|
|
|
__zfs_complete_ordered_arguments "$(__zpool_get_properties)" "$(__zpool_list_pools)" "$cur"
|
2014-07-19 03:45:49 +04:00
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
import)
|
|
|
|
if [[ $prev == -d ]]
|
|
|
|
then
|
|
|
|
_filedir -d
|
|
|
|
else
|
2021-11-30 21:23:10 +03:00
|
|
|
mapfile -t COMPREPLY < <(compgen -W "$(__zpool_list_pools) -d" -- "$cur")
|
2014-07-19 03:45:49 +04:00
|
|
|
fi
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
set)
|
2021-05-22 00:43:38 +03:00
|
|
|
__zfs_complete_ordered_arguments "$(__zpool_get_editable_properties)" "$(__zpool_list_pools)" "$cur"
|
2020-06-16 22:27:23 +03:00
|
|
|
__zfs_complete_nospace
|
2014-07-19 03:45:49 +04:00
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
add|attach|clear|create|detach|offline|online|remove|replace)
|
2021-05-22 00:43:38 +03:00
|
|
|
pools="$(__zpool_list_pools)"
|
|
|
|
# shellcheck disable=SC2086
|
2014-07-19 03:45:49 +04:00
|
|
|
if __zfs_argument_chosen $pools
|
|
|
|
then
|
|
|
|
_filedir
|
|
|
|
else
|
2021-11-30 21:23:10 +03:00
|
|
|
mapfile -t COMPREPLY < <(compgen -W "$pools" -- "$cur")
|
2014-07-19 03:45:49 +04:00
|
|
|
fi
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
*)
|
2021-11-30 21:23:10 +03:00
|
|
|
mapfile -t COMPREPLY < <(compgen -W "$(__zpool_list_pools)" -- "$cur")
|
2014-07-19 03:45:49 +04:00
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
complete -F __zfs_complete zfs
|
|
|
|
complete -F __zpool_complete zpool
|