File LVM-completion-bsc946875.patch of Package bash-completion
There are the following problems with lvm completions:
1)_lvm_physicalvolumes() only gets PVs that belong to a VG. In some
cases like pvremove we can use all PVs including those not included
in any VGs.
solution: Add _lvm_physicalvolumes_all to get all PVs and correct
all the commands.
2)pvcreate should be able to use all block devcices.
solution: Add _lvm_filedir() to use _filedir except set $cur to /dev
when $cur is empty.
3)when /etc/lvm/lvm.conf silent is 1 there is no output for vg/lv/pvscan,
bash-completion will not work.
solution: Check the value of silent option. If it is 1 then temporarily
set silent 0 and recover back to 1 after the command executed.
Signed-off-by: Liuhua Wang <lwang@suse.com>
Reviewed-by: Lidong Zhong <lzhong@suse.com>
Index: bash-completion-2.11/completions/lvm
===================================================================
---
bash-completion-2.12.0/completions/lvm | 26 ++++++++++++++++++++------
1 file changed, 20 insertions(+), 6 deletions(-)
--- bash-completion-2.12.0/completions/lvm
+++ bash-completion-2.12.0/completions/lvm 2024-02-23 08:05:52.542682924 +0000
@@ -5,27 +5,41 @@ _comp_cmd_lvm__filedir()
_comp_compgen -c "${cur:-/dev/}" filedir
}
+_comp_cmd_lvm__verbose()
+{
+ local silent=$(sed -n -e "s|^[ \t]*silent[ \t]*=[ \t]*\([01]\)|\1|p" /etc/lvm/lvm.conf)
+ test ${silent:-0} -eq 1
+}
+
_comp_cmd_lvm__volumegroups()
{
- _comp_compgen_split -- "$(vgscan 2>/dev/null |
+ local verbose
+ _comp_cmd_lvm__verbose && verbose=-v
+ _comp_compgen_split -- "$(vgscan $verbose 2>/dev/null |
command sed -n -e 's|.*Found.*"\(.*\)".*$|\1|p')"
}
_comp_cmd_lvm__physicalvolumes_all()
{
- _comp_compgen_split -- "$(pvscan 2>/dev/null |
+ local verbose
+ _comp_cmd_lvm__verbose && verbose=-v
+ _comp_compgen_split -- "$(pvscan $verbose 2>/dev/null |
command sed -n -e 's|^.*PV \([^ ]*\) .*|\1|p')"
}
_comp_cmd_lvm__physicalvolumes()
{
- _comp_compgen_split -- "$(pvscan 2>/dev/null |
+ local verbose
+ _comp_cmd_lvm__verbose && verbose=-v
+ _comp_compgen_split -- "$(pvscan $verbose 2>/dev/null |
command sed -n -e 's|^.*PV \(.*\) VG.*$|\1|p')"
}
_comp_cmd_lvm__logicalvolumes()
{
- _comp_compgen_split -- "$(lvscan 2>/dev/null |
+ local verbose
+ _comp_cmd_lvm__verbose && verbose=-v
+ _comp_compgen_split -- "$(lvscan $verbose 2>/dev/null |
command sed -n -e "s|^.*'\(.*\)'.*$|\1|p")"
if [[ $cur == /dev/mapper/* ]]; then
_comp_compgen -a filedir
@@ -403,7 +417,7 @@ _comp_cmd_vgreduce()
if ((REPLY == 0)); then
_comp_cmd_lvm__volumegroups
else
- _comp_cmd_lvm__physicalvolumes
+ _comp_cmd_lvm__physicalvolumes_all
fi
fi
} &&
@@ -735,7 +749,7 @@ _comp_cmd_lvcreate()
if ((REPLY == 0)); then
_comp_cmd_lvm__volumegroups
else
- _comp_cmd_lvm__physicalvolumes
+ _comp_cmd_lvm__physicalvolumes_all
fi
fi
} &&