+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.
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
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%=*}";;
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
-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
-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