]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
Add function to get completions from usage.
authorYves Blusseau <blusseau@zetam.org>
Wed, 15 Sep 2010 09:46:16 +0000 (11:46 +0200)
committerYves Blusseau <blusseau@zetam.org>
Wed, 15 Sep 2010 09:46:16 +0000 (11:46 +0200)
    * util/bash-completion.d/grub-completion.bash.in: Add function to get
    completions from usage. Use LC_ALL=C to get options properly.

ChangeLog
ChangeLog.completion-usage [new file with mode: 0644]
util/bash-completion.d/grub-completion.bash.in

index c525fe3695ff99bdc087a83e2a9e38b686d7b71f..1113b8157df1cf4d21eb005c7eb55840c184bb08 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/ChangeLog.completion-usage b/ChangeLog.completion-usage
new file mode 100644 (file)
index 0000000..eee7b01
--- /dev/null
@@ -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.
index abba0df78fa6d367835e7214ccc20f7123323eb3..65cbb80ee0faae72c2c20129d4f5f8ec816035ad 100644 (file)
@@ -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