Revision 632d5090 autotools/build-bash-completion

b/autotools/build-bash-completion
183 183
  sw.Write("}")
184 184

  
185 185

  
186
def WriteCompReply(sw, args):
187
  sw.Write("""COMPREPLY=( $(compgen %s -- "$cur") )""", args)
186
def WriteCompReply(sw, args, cur="\"$cur\""):
187
  sw.Write("""COMPREPLY=( $(compgen %s -- %s) )""", args, cur)
188 188
  sw.Write("return")
189 189

  
190 190

  
......
257 257
    sw.Write("if [[ $COMP_CWORD -gt %s ]]; then", self.arg_offset + 1)
258 258
    sw.IncIndent()
259 259
    try:
260
      # --foo value
260 261
      sw.Write("""case "$prev" in""")
261 262
      for (choices, names) in values.iteritems():
262
        # TODO: Implement completion for --foo=bar form
263 263
        sw.Write("%s)", "|".join([utils.ShellQuote(i) for i in names]))
264 264
        sw.IncIndent()
265 265
        try:
......
272 272
      sw.DecIndent()
273 273
    sw.Write("""fi""")
274 274

  
275
    # --foo=value
276
    values_longopts = {}
277

  
278
    for (choices, names) in values.iteritems():
279
      longnames = [i for i in names if i.startswith("--")]
280
      if longnames:
281
        values_longopts[choices] = longnames
282

  
283
    if values_longopts:
284
      sw.Write("""case "$cur" in""")
285
      for (choices, names) in values_longopts.iteritems():
286
        sw.Write("%s)", "|".join([utils.ShellQuote(i) + "=*" for i in names]))
287
        sw.IncIndent()
288
        try:
289
          # Shell expression to get option value
290
          cur="\"${cur#--*=}\""
291
          WriteCompReply(sw, "-W %s" % utils.ShellQuote(choices), cur=cur)
292
        finally:
293
          sw.DecIndent()
294
        sw.Write(";;")
295
      sw.Write("""esac""")
296

  
275 297
  def _CompleteArguments(self, sw):
276 298
    if not (self.opts or self.args):
277 299
      return
......
394 416
  sw.IncIndent()
395 417
  try:
396 418
    sw.Write("local "
397
             ' cur="${COMP_WORDS[$COMP_CWORD]}"'
419
             ' cur="${COMP_WORDS[COMP_CWORD]}"'
398 420
             ' prev="${COMP_WORDS[COMP_CWORD-1]}"'
399 421
             ' i first_arg_idx choices compgenargs arg_idx')
400 422

  

Also available in: Unified diff