Add function to get completions from usage.

* util/bash-completion.d/grub-completion.bash.in: Add function to get
    completions from usage. Use LC_ALL=C to get options properly.
This commit is contained in:
Yves Blusseau 2010-09-15 11:46:16 +02:00
parent 2e04a00685
commit 2b94e3ff6e
3 changed files with 37 additions and 4 deletions

View file

@ -1,3 +1,10 @@
2010-09-15 Yves Blusseau <blusseau@zetam.org>
Add function to get completions from usage.
* util/bash-completion.d/grub-completion.bash.in: Add function to get
completions from usage. Use LC_ALL=C to get options properly.
2010-09-15 Vladimir Serbinenko <phcoder@gmail.com> 2010-09-15 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/gnulib/basename-lgpl.c: Imported. * grub-core/gnulib/basename-lgpl.c: Imported.

View file

@ -0,0 +1,4 @@
2010-09-15 Yves Blusseau <blusseau@zetam.org>
* util/bash-completion.d/grub-completion.bash.in: Add function to get
completions from usage.

View file

@ -58,7 +58,7 @@ __grubcomp () {
esac esac
} }
# Function that return long options from the help # Function that return long options from the help of the command
# - arg: $1 (optional) command to get the long options from # - arg: $1 (optional) command to get the long options from
__grub_get_options_from_help () { __grub_get_options_from_help () {
local prog local prog
@ -70,7 +70,7 @@ __grub_get_options_from_help () {
fi fi
local i IFS=" "$'\t'$'\n' local i IFS=" "$'\t'$'\n'
for i in $($prog --help) for i in $(LC_ALL=C $prog --help)
do do
case $i in case $i in
--*) echo "${i%=*}";; --*) echo "${i%=*}";;
@ -78,6 +78,28 @@ __grub_get_options_from_help () {
done done
} }
# Function that return long options from the usage of the command
# - arg: $1 (optional) command to get the long options from
__grub_get_options_from_usage () {
local prog
if [ $# -ge 1 ]; then
prog="$1"
else
prog="${COMP_WORDS[0]}"
fi
local i IFS=" "$'\t'$'\n'
for i in $(LC_ALL=C $prog --usage)
do
case $i in
\[--*\]) i=${i#[} # Remove leading [
echo ${i%%?(=*)]} # Remove optional value and trailing ]
;;
esac
done
}
__grub_get_last_option () { __grub_get_last_option () {
local i local i
for (( i=$COMP_CWORD-1; i > 0; i-- )); do for (( i=$COMP_CWORD-1; i > 0; i-- )); do
@ -355,7 +377,7 @@ _grub_mkimage () {
-O|--format) -O|--format)
# Get available format from help # Get available format from help
local prog=${COMP_WORDS[0]} local prog=${COMP_WORDS[0]}
__grubcomp "$($prog --help | \ __grubcomp "$(LC_ALL=C $prog --help | \
awk -F ":" '/available formats/ { print $2 }' | \ awk -F ":" '/available formats/ { print $2 }' | \
sed 's/, / /g')" sed 's/, / /g')"
return return
@ -415,7 +437,7 @@ _grub_probe () {
-t|--target) -t|--target)
# Get target type from help # Get target type from help
local prog=${COMP_WORDS[0]} local prog=${COMP_WORDS[0]}
__grubcomp "$($prog --help | \ __grubcomp "$(LC_ALL=C $prog --help | \
awk -F "[()]" '/--target=/ { print $2 }' | \ awk -F "[()]" '/--target=/ { print $2 }' | \
sed 's/|/ /g')" sed 's/|/ /g')"
return return