[Bash-completion-devel] [PATCH 3/3] lvm: disable silent temporarily to avoid no output
Liuhua Wang
lwang at suse.com
Mon Mar 7 09:56:32 UTC 2016
bash-completion will not work when /etc/lvm/lvm.conf silent is 1
because there is no output for vg/lv/pvscan.
So we 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 at suse.com>
Reviewed-by: Lidong Zhong <lzhong at suse.com>
---
completions/lvm | 32 ++++++++++++++++++++++++++++++--
1 file changed, 30 insertions(+), 2 deletions(-)
diff --git a/completions/lvm b/completions/lvm
index e213967..e0c83bd 100644
--- a/completions/lvm
+++ b/completions/lvm
@@ -8,24 +8,50 @@ _lvm_filedir()
_lvm_volumegroups()
{
+ local silent
+ silent=$(sed -n -e "s|^[ \t]*silent[ \t]*=[ \t]*\([01]\)|\1|p" /etc/lvm/lvm.conf)
+ silent=${silent:-0}
+ [ $silent -eq 1 ] && sed -i "s|\(^[ \t]*silent[ \t]*=[ \t]*\)[01].*$|\10|" /etc/lvm/lvm.conf
+
COMPREPLY=( $(compgen -W "$( vgscan 2>/dev/null | \
sed -n -e 's|.*Found.*"\(.*\)".*$|\1|p' )" -- "$cur" ) )
+
+ [ $silent -eq 1 ] && sed -i "s|\(^[ \t]*silent[ \t]*=[ \t]*\)[01].*$|\11|" /etc/lvm/lvm.conf
}
_lvm_physicalvolumes_all()
{
- COMPREPLY=( $(compgen -W "$( pvscan 2>/dev/null | \
- sed -n -e 's|^.*PV \([^ ]*\) .*|\1|p' )" -- "$cur" ) )
+ local silent
+ silent=$(sed -n -e "s|^[ \t]*silent[ \t]*=[ \t]*\([01]\)|\1|p" /etc/lvm/lvm.conf)
+ silent=${silent:-0}
+ [ $silent -eq 1 ] && sed -i "s|\(^[ \t]*silent[ \t]*=[ \t]*\)[01].*$|\10|" /etc/lvm/lvm.conf
+
+ COMPREPLY=( $(compgen -W "$( pvscan 2>/dev/null | \
+ sed -n -e 's|^.*PV \([^ ]*\) .*|\1|p' )" -- "$cur" ) )
+
+ [ $silent -eq 1 ] && sed -i "s|\(^[ \t]*silent[ \t]*=[ \t]*\)[01].*$|\11|" /etc/lvm/lvm.conf
}
_lvm_physicalvolumes()
{
+ local silent
+ silent=$(sed -n -e "s|^[ \t]*silent[ \t]*=[ \t]*\([01]\)|\1|p" /etc/lvm/lvm.conf)
+ silent=${silent:-0}
+ [ $silent -eq 1 ] && sed -i "s|\(^[ \t]*silent[ \t]*=[ \t]*\)[01].*$|\10|" /etc/lvm/lvm.conf
+
COMPREPLY=( $(compgen -W "$( pvscan 2>/dev/null | \
sed -n -e 's|^.*PV \(.*\) VG.*$|\1|p' )" -- "$cur" ) )
+
+ [ $silent -eq 1 ] && sed -i "s|\(^[ \t]*silent[ \t]*=[ \t]*\)[01].*$|\11|" /etc/lvm/lvm.conf
}
_lvm_logicalvolumes()
{
+ local silent
+ silent=$(sed -n -e "s|^[ \t]*silent[ \t]*=[ \t]*\([01]\)|\1|p" /etc/lvm/lvm.conf)
+ silent=${silent:-0}
+ [ $silent -eq 1 ] && sed -i "s|\(^[ \t]*silent[ \t]*=[ \t]*\)[01].*$|\10|" /etc/lvm/lvm.conf
+
COMPREPLY=( $(compgen -W "$( lvscan 2>/dev/null | \
sed -n -e "s|^.*'\(.*\)'.*$|\1|p" )" -- "$cur" ) )
if [[ $cur == /dev/mapper/* ]]; then
@@ -35,6 +61,8 @@ _lvm_logicalvolumes()
[[ ${COMPREPLY[i]} == */control ]] && unset 'COMPREPLY[i]'
done
fi
+
+ [ $silent -eq 1 ] && sed -i "s|\(^[ \t]*silent[ \t]*=[ \t]*\)[01].*$|\11|" /etc/lvm/lvm.conf
}
_lvm_units()
--
1.8.4.5
More information about the Bash-completion-devel
mailing list