File LVM-completion-bsc946875.patch of Package bash-completion.9255

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>






diff --git a/completions/lvm b/completions/lvm
--- a/completions/lvm
+++ b/completions/lvm
@@ -6,27 +6,41 @@
     _filedir
 }
 
+_lvm_verbose()
+{
+    local silent=$(sed -n -e "s|^[ \t]*silent[ \t]*=[ \t]*\([01]\)|\1|p" /etc/lvm/lvm.conf)
+    test ${silent:-0} -eq 1
+}
+
 _lvm_volumegroups()
 {
-    COMPREPLY=( $(compgen -W "$( vgscan 2>/dev/null | \
+    local verbose
+    _lvm_verbose && verbose=-v
+    COMPREPLY=( $(compgen -W "$( vgscan $verbose 2>/dev/null | \
         command sed -n -e 's|.*Found.*"\(.*\)".*$|\1|p' )" -- "$cur" ) )
 }
 
 _lvm_physicalvolumes_all()
 {
-    COMPREPLY=( $(compgen -W "$( pvscan 2>/dev/null | \
+    local verbose
+    _lvm_verbose && verbose=-v
+    COMPREPLY=( $(compgen -W "$( pvscan $verbose 2>/dev/null | \
         command sed -n -e 's|^.*PV \([^ ]*\) .*|\1|p' )" -- "$cur" ) )
 }
 
 _lvm_physicalvolumes()
 {
-    COMPREPLY=( $(compgen -W "$( pvscan 2>/dev/null | \
+    local verbose
+    _lvm_verbose && verbose=-v
+    COMPREPLY=( $(compgen -W "$( pvscan $verbose 2>/dev/null | \
         command sed -n -e 's|^.*PV \(.*\) VG.*$|\1|p' )" -- "$cur" ) )
 }
 
 _lvm_logicalvolumes()
 {
-    COMPREPLY=( $(compgen -W "$( lvscan 2>/dev/null | \
+    local verbose
+    _lvm_verbose && verbose=-v
+    COMPREPLY=( $(compgen -W "$( lvscan $verbose 2>/dev/null | \
         command sed -n -e "s|^.*'\(.*\)'.*$|\1|p" )" -- "$cur" ) )
     if [[ $cur == /dev/mapper/* ]]; then
         _filedir
@@ -394,7 +408,7 @@
         if [[ $args -eq 0 ]]; then
             _lvm_volumegroups
         else
-            _lvm_physicalvolumes
+            _lvm_physicalvolumes_all
         fi
     fi
 } &&
@@ -709,7 +723,7 @@
         if [[ $args -eq 0 ]]; then
             _lvm_volumegroups
         else
-            _lvm_physicalvolumes
+            _lvm_physicalvolumes_all
         fi
     fi
 } &&
openSUSE Build Service is sponsored by