mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2024-12-26 03:09:34 +03:00
contrib/bash_completion.d: fix obvious shellcheck problems
Reviewed-by: John Kennedy <john.kennedy@delphix.com> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz> Closes #12042
This commit is contained in:
parent
359b6cca0f
commit
9627bdc697
@ -62,24 +62,25 @@ __zfs_list_filesystems()
|
|||||||
|
|
||||||
__zfs_match_snapshot()
|
__zfs_match_snapshot()
|
||||||
{
|
{
|
||||||
local base_dataset=${cur%@*}
|
local base_dataset="${cur%@*}"
|
||||||
if [[ $base_dataset != $cur ]]
|
if [ "$base_dataset" != "$cur" ]
|
||||||
then
|
then
|
||||||
$__ZFS_CMD list -H -o name -s name -t snapshot -d 1 $base_dataset
|
$__ZFS_CMD list -H -o name -s name -t snapshot -d 1 "$base_dataset"
|
||||||
else
|
else
|
||||||
if [[ $cur != "" ]] && __zfs_list_datasets $cur &> /dev/null
|
if [ "$cur" != "" ] && __zfs_list_datasets "$cur" &> /dev/null
|
||||||
then
|
then
|
||||||
$__ZFS_CMD list -H -o name -s name -t filesystem -r $cur | tail -n +2
|
$__ZFS_CMD list -H -o name -s name -t filesystem -r "$cur" | tail -n +2
|
||||||
# We output the base dataset name even though we might be
|
# We output the base dataset name even though we might be
|
||||||
# completing a command that can only take a snapshot, because it
|
# completing a command that can only take a snapshot, because it
|
||||||
# prevents bash from considering the completion finished when it
|
# prevents bash from considering the completion finished when it
|
||||||
# ends in the bare @.
|
# ends in the bare @.
|
||||||
echo $cur
|
echo "$cur"
|
||||||
echo $cur@
|
echo "$cur@"
|
||||||
else
|
else
|
||||||
local datasets=$(__zfs_list_datasets)
|
local datasets
|
||||||
|
datasets="$(__zfs_list_datasets)"
|
||||||
# As above
|
# As above
|
||||||
echo $datasets
|
echo "$datasets"
|
||||||
if [[ "$cur" == */ ]]
|
if [[ "$cur" == */ ]]
|
||||||
then
|
then
|
||||||
# If the current command ends with a slash, then the only way
|
# If the current command ends with a slash, then the only way
|
||||||
@ -89,54 +90,56 @@ __zfs_match_snapshot()
|
|||||||
local num_children
|
local num_children
|
||||||
# This is actually off by one as zfs list includes the named
|
# This is actually off by one as zfs list includes the named
|
||||||
# dataset in addition to its children
|
# dataset in addition to its children
|
||||||
num_children=$(__zfs_list_datasets -d 1 ${cur%/} 2> /dev/null | wc -l)
|
num_children=$(__zfs_list_datasets -d 1 "${cur%/}" 2> /dev/null | wc -l)
|
||||||
if [[ $num_children != 2 ]]
|
if [[ $num_children != 2 ]]
|
||||||
then
|
then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
echo "$datasets" | awk '{print $1"@"}'
|
echo "$datasets" | awk '{print $1 "@"}'
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
__zfs_match_snapshot_or_bookmark()
|
__zfs_match_snapshot_or_bookmark()
|
||||||
{
|
{
|
||||||
local base_dataset=${cur%[#@]*}
|
local base_dataset="${cur%[#@]*}"
|
||||||
if [[ $base_dataset != $cur ]]
|
if [ "$base_dataset" != "$cur" ]
|
||||||
then
|
then
|
||||||
if [[ $cur == *@* ]]
|
if [[ $cur == *@* ]]
|
||||||
then
|
then
|
||||||
$__ZFS_CMD list -H -o name -s name -t snapshot -d 1 $base_dataset
|
$__ZFS_CMD list -H -o name -s name -t snapshot -d 1 "$base_dataset"
|
||||||
else
|
else
|
||||||
$__ZFS_CMD list -H -o name -s name -t bookmark -d 1 $base_dataset
|
$__ZFS_CMD list -H -o name -s name -t bookmark -d 1 "$base_dataset"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
$__ZFS_CMD list -H -o name -s name -t filesystem,volume
|
$__ZFS_CMD list -H -o name -s name -t filesystem,volume
|
||||||
if [[ $cur != "" ]] && $__ZFS_CMD list -H -o name -s name -t filesystem,volume $cur &> /dev/null
|
if [ -e "$cur" ] && $__ZFS_CMD list -H -o name -s name -t filesystem,volume "$cur" &> /dev/null
|
||||||
then
|
then
|
||||||
echo $cur@
|
echo "$cur@"
|
||||||
echo $cur#
|
echo "$cur#"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
__zfs_match_multiple_snapshots()
|
__zfs_match_multiple_snapshots()
|
||||||
{
|
{
|
||||||
local existing_opts=$(expr "$cur" : '\(.*\)[%,]')
|
local existing_opts
|
||||||
if [[ $existing_opts ]]
|
existing_opts="$(expr "$cur" : '\(.*\)[%,]')"
|
||||||
|
if [ -e "$existing_opts" ]
|
||||||
then
|
then
|
||||||
local base_dataset=${cur%@*}
|
local base_dataset="${cur%@*}"
|
||||||
if [[ $base_dataset != $cur ]]
|
if [ "$base_dataset" != "$cur" ]
|
||||||
then
|
then
|
||||||
local cur=${cur##*,}
|
local cur="${cur##*,}"
|
||||||
if [[ $cur =~ ^%|%.*% ]]
|
if [[ $cur =~ ^%|%.*% ]]
|
||||||
then
|
then
|
||||||
# correct range syntax is start%end
|
# correct range syntax is start%end
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
local range_start=$(expr "$cur" : '\(.*%\)')
|
local range_start
|
||||||
$__ZFS_CMD list -H -o name -s name -t snapshot -d 1 $base_dataset | sed 's$.*@$'$range_start'$g'
|
range_start="$(expr "$cur" : '\(.*%\)')"
|
||||||
|
$__ZFS_CMD list -H -o name -s name -t snapshot -d 1 "$base_dataset" | sed 's$.*@$'"$range_start"'$g'
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
__zfs_match_snapshot_or_bookmark
|
__zfs_match_snapshot_or_bookmark
|
||||||
|
Loading…
Reference in New Issue
Block a user