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:
parent
2e04a00685
commit
2b94e3ff6e
3 changed files with 37 additions and 4 deletions
|
@ -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>
|
||||
|
||||
* grub-core/gnulib/basename-lgpl.c: Imported.
|
||||
|
|
4
ChangeLog.completion-usage
Normal file
4
ChangeLog.completion-usage
Normal 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.
|
|
@ -58,7 +58,7 @@ __grubcomp () {
|
|||
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
|
||||
__grub_get_options_from_help () {
|
||||
local prog
|
||||
|
@ -70,7 +70,7 @@ __grub_get_options_from_help () {
|
|||
fi
|
||||
|
||||
local i IFS=" "$'\t'$'\n'
|
||||
for i in $($prog --help)
|
||||
for i in $(LC_ALL=C $prog --help)
|
||||
do
|
||||
case $i in
|
||||
--*) echo "${i%=*}";;
|
||||
|
@ -78,6 +78,28 @@ __grub_get_options_from_help () {
|
|||
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 () {
|
||||
local i
|
||||
for (( i=$COMP_CWORD-1; i > 0; i-- )); do
|
||||
|
@ -355,7 +377,7 @@ _grub_mkimage () {
|
|||
-O|--format)
|
||||
# Get available format from help
|
||||
local prog=${COMP_WORDS[0]}
|
||||
__grubcomp "$($prog --help | \
|
||||
__grubcomp "$(LC_ALL=C $prog --help | \
|
||||
awk -F ":" '/available formats/ { print $2 }' | \
|
||||
sed 's/, / /g')"
|
||||
return
|
||||
|
@ -415,7 +437,7 @@ _grub_probe () {
|
|||
-t|--target)
|
||||
# Get target type from help
|
||||
local prog=${COMP_WORDS[0]}
|
||||
__grubcomp "$($prog --help | \
|
||||
__grubcomp "$(LC_ALL=C $prog --help | \
|
||||
awk -F "[()]" '/--target=/ { print $2 }' | \
|
||||
sed 's/|/ /g')"
|
||||
return
|
||||
|
|
Loading…
Reference in a new issue