From a10caf87a59b8ad16b9d234bc9b0175dfe6f0c5a Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Mon, 26 Oct 2009 19:22:00 +0100
Subject: [PATCH] bash_completion: Move common code into function

This reduces the size of the script by about 9 kB.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 autotools/build-bash-completion | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/autotools/build-bash-completion b/autotools/build-bash-completion
index c94ad261b..0d03cf83c 100755
--- a/autotools/build-bash-completion
+++ b/autotools/build-bash-completion
@@ -236,10 +236,20 @@ def WritePreamble(sw):
     sw.DecIndent()
   sw.Write("}")
 
+  # Params: <compgen options>
+  # Result variable: $COMPREPLY
+  sw.Write("_ganeti_compgen() {")
+  sw.IncIndent()
+  try:
+    sw.Write("""COMPREPLY=( $(compgen "$@") )""")
+    sw.Write("_ganeti_dbglog COMPREPLY=\"${COMPREPLY[@]}\"")
+  finally:
+    sw.DecIndent()
+  sw.Write("}")
+
 
 def WriteCompReply(sw, args, cur="\"$cur\""):
-  sw.Write("""COMPREPLY=( $(compgen %s -- %s) )""", args, cur)
-  sw.Write("_ganeti_dbglog COMPREPLY=\"${COMPREPLY[@]}\"")
+  sw.Write("_ganeti_compgen %s -- %s", args, cur)
   sw.Write("return")
 
 
-- 
GitLab