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 <lw...@suse.com> Reviewed-by: Lidong Zhong <lzh...@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 _______________________________________________ Bash-completion-devel mailing list Bash-completion-devel@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/bash-completion-devel