Dr. Werner Fink 2015-12-18 09:35:44 +00:00 committed by Git OBS Bridge
parent 0fa25174cc
commit 9caef6e1ab
5 changed files with 196 additions and 140 deletions

View File

@ -1,171 +1,153 @@
---
completions/lvm | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
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.
--- completions/lvm
+++ completions/lvm 2015-09-23 11:55:33.862917000 +0000
@@ -25,6 +25,12 @@ _lvm_logicalvolumes()
fi
}
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
@@ -1,19 +1,57 @@
# bash completion for lvm -*- shell-script -*-
+_lvm_filedir()
+{
+ test -n "$COMPREPLY" && return
+ COMPREPLY+=( $( compgen -f -d -- "${cur:-/dev/}" ) )
+ cur=${cur:-/dev/}
+ _filedir
+}
+
_lvm_units()
_lvm_volumegroups()
{
COMPREPLY=( $( compgen -W 'h s b k m g t H K M G T' -- "$cur" ) )
@@ -98,6 +104,7 @@ _pvs()
else
_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 "$( 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()
+{
+ 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
@@ -23,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()
@@ -96,7 +136,7 @@ _pvs()
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_usage "$1" --help )' -- "$cur" ) )
else
- _lvm_physicalvolumes
+ _lvm_physicalvolumes_all
fi
+ _lvm_filedir
} &&
complete -F _pvs pvs
@@ -118,6 +125,7 @@ _pvdisplay()
@@ -116,7 +156,7 @@ _pvdisplay()
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_usage "$1" --help )' -- "$cur" ) )
else
_lvm_physicalvolumes
- _lvm_physicalvolumes
+ _lvm_physicalvolumes_all
fi
+ _lvm_filedir
} &&
complete -F _pvdisplay pvdisplay
@@ -138,6 +146,7 @@ _pvchange()
@@ -136,7 +176,7 @@ _pvchange()
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_usage "$1" --help )' -- "$cur" ) )
else
_lvm_physicalvolumes
- _lvm_physicalvolumes
+ _lvm_physicalvolumes_all
fi
+ _lvm_filedir
} &&
complete -F _pvchange pvchange
@@ -170,6 +179,7 @@ _pvcreate()
@@ -168,7 +208,7 @@ _pvcreate()
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_usage "$1" --help )' -- "$cur" ) )
else
_lvm_physicalvolumes
- _lvm_physicalvolumes
+ _lvm_filedir
fi
+ _lvm_filedir
} &&
complete -F _pvcreate pvcreate
@@ -195,6 +205,7 @@ _pvmove()
@@ -206,7 +246,7 @@ _pvremove()
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_usage "$1" --help )' -- "$cur" ) )
else
_lvm_physicalvolumes
- _lvm_physicalvolumes
+ _lvm_physicalvolumes_all
fi
+ _lvm_filedir
} &&
complete -F _pvmove pvmove
@@ -208,6 +219,7 @@ _pvremove()
else
_lvm_physicalvolumes
fi
+ _lvm_filedir
} &&
complete -F _pvremove pvremove
@@ -325,6 +337,7 @@ _vgcreate()
_lvm_physicalvolumes
@@ -322,7 +362,7 @@ _vgcreate()
if [[ $args -eq 0 ]]; then
_lvm_volumegroups
else
- _lvm_physicalvolumes
+ _lvm_physicalvolumes_all
fi
fi
+ _lvm_filedir
} &&
complete -F _vgcreate vgcreate
@@ -385,6 +398,7 @@ _vgreduce()
_lvm_physicalvolumes
@@ -412,7 +452,7 @@ _vgextend()
if [[ $args -eq 0 ]]; then
_lvm_volumegroups
else
- _lvm_physicalvolumes
+ _lvm_physicalvolumes_all
fi
fi
+ _lvm_filedir
} &&
complete -F _vgreduce vgreduce
@@ -415,6 +429,7 @@ _vgextend()
_lvm_physicalvolumes
fi
fi
+ _lvm_filedir
} &&
complete -F _vgextend vgextend
@@ -568,6 +583,7 @@ _vgsplit()
_lvm_physicalvolumes
fi
fi
+ _lvm_filedir
} &&
complete -F _vgsplit vgsplit
@@ -618,6 +634,7 @@ _lvs()
else
_lvm_logicalvolumes
fi
+ _lvm_filedir
} &&
complete -F _lvs lvs
@@ -638,6 +655,7 @@ _lvdisplay()
else
_lvm_logicalvolumes
fi
+ _lvm_filedir
} &&
complete -F _lvdisplay lvdisplay
@@ -662,6 +680,7 @@ _lvchange()
else
_lvm_logicalvolumes
fi
+ _lvm_filedir
} &&
complete -F _lvchange lvchange
@@ -700,6 +719,7 @@ _lvcreate()
_lvm_physicalvolumes
fi
fi
+ _lvm_filedir
} &&
complete -F _lvcreate lvcreate
@@ -720,6 +740,7 @@ _lvremove()
else
_lvm_logicalvolumes
fi
+ _lvm_filedir
} &&
complete -F _lvremove lvremove
@@ -740,6 +761,7 @@ _lvrename()
else
_lvm_logicalvolumes
fi
+ _lvm_filedir
} &&
complete -F _lvrename lvrename
@@ -764,6 +786,7 @@ _lvreduce()
else
_lvm_logicalvolumes
fi
+ _lvm_filedir
} &&
complete -F _lvreduce lvreduce
@@ -794,6 +817,7 @@ _lvresize()
_lvm_physicalvolumes
fi
fi
+ _lvm_filedir
} &&
complete -F _lvresize lvresize
@@ -824,6 +848,7 @@ _lvextend()
_lvm_physicalvolumes
fi
fi
+ _lvm_filedir
} &&
complete -F _lvextend lvextend

View File

@ -1,3 +1,13 @@
-------------------------------------------------------------------
Fri Dec 18 09:33:05 UTC 2015 - werner@suse.de
- Add patch respect-variables-boo940837.patch to avoid completions
which results in e.g. ls \$HO
- Add patch rm-completion-smart-boo958462.patch to allow completions
list e.g. rm prefix*.jpg<TAB><TAB>
- Modify patch LVM-completion-bsc946875.patch that is add the
new patch from Liuhua Wang
-------------------------------------------------------------------
Wed Sep 23 11:58:33 UTC 2015 - werner@suse.de

View File

@ -41,6 +41,10 @@ Patch5: ls-completion-boo889319.patch
Patch6: backtick-completion-boo940835.patch
# PATCH-FIX-SUSE bsc#946875
Patch7: LVM-completion-bsc946875.patch
# PATCH-FIX-SUSE boo#940837, bsc#959299
Patch8: respect-variables-boo940837.patch
# PATCH-FIX-SUSE boo#958462
Patch9: rm-completion-smart-boo958462.patch
BuildRequires: pkg-config
Requires: bash
BuildRoot: %{_tmppath}/%{name}-%{version}-build
@ -59,7 +63,9 @@ of the programmable completion feature of Bash 2.04 and later.
%patch4 -b .p4
%patch5 -b .p5
%patch6 -b .p6
%patch7 -b .p7
%patch7 -b .p7 -p1
%patch8 -b .p8
%patch9 -b .p9
%build
%configure

View File

@ -0,0 +1,34 @@
Bug boo#940837
Bug bsc#959299
That is do not escape the dollar character of a variable to allow
commands like `ls' to go further in its completion chain.
---
bash_completion | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
--- bash_completion
+++ bash_completion 2015-12-18 09:53:36.647442000 +0100
@@ -1798,8 +1798,19 @@ _complete_as_root()
_longopt()
{
- local cur prev words cword split
- _init_completion -s || return
+ local cur=${COMP_WORDS[COMP_CWORD]}
+ local prev words cword split
+
+ if [[ "${cur:0:1}" == '$' ]] ; then
+ compopt -o dirnames +o filenames
+ else
+ compopt +o dirnames -o filenames
+ fi
+
+ if ! _init_completion -s ; then
+ _dollar $cur
+ return
+ fi
case "${prev,,}" in
--help|--usage|--version)

View File

@ -0,0 +1,24 @@
Bug boo#958462
Allow the smart bash builtin completion if normal completion scripting
does not return anything.
---
bash_completion | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
--- bash_completion
+++ bash_completion 2015-12-18 09:17:57.865910263 +0000
@@ -1857,10 +1857,11 @@ _longopt()
complete -F _longopt -o filenames a2ps awk base64 bash bc bison cat colordiff cp csplit \
cut date df diff dir du enscript expand fmt fold gperf \
grep grub head indent irb ld ldd less ln m4 md5sum mkdir mkfifo mknod \
- mv nl nm objcopy objdump od paste pr ptx readelf rm rmdir \
+ mv nl nm objcopy objdump od paste pr ptx readelf \
sed sha{,1,224,256,384,512}sum shar sort split strip sum tac tail tee \
texindex touch tr unexpand uniq vdir wc who
complete -F _longopt -o default env netstat seq uname units
+complete -F _longopt -o bashdefault -o default -o filenames -o nospace rm rmdir
if typeset -F _ls_ &> /dev/null; then
complete -o bashdefault -o default -o filenames -o nospace -F _ls_ ls ll la l ls-l lf