Revision b33cad4a autotools/build-bash-completion

b/autotools/build-bash-completion
553 553
        sw.DecIndent()
554 554
      sw.Write("fi")
555 555

  
556
      # We're doing options and arguments to commands
557
      sw.Write("""case "${COMP_WORDS[1]}" in""")
556
      # Group commands by arguments and options
557
      grouped_cmds = {}
558 558
      for cmd, (_, argdef, optdef, _, _) in commands.iteritems():
559 559
        if not (argdef or optdef):
560 560
          continue
561
        grouped_cmds.setdefault((tuple(argdef), tuple(optdef)), set()).add(cmd)
561 562

  
562
        # TODO: Group by arguments and options
563
        sw.Write("%s)", utils.ShellQuote(cmd))
563
      # We're doing options and arguments to commands
564
      sw.Write("""case "${COMP_WORDS[1]}" in""")
565
      for ((argdef, optdef), cmds) in grouped_cmds.items():
566
        assert argdef or optdef
567
        sw.Write("%s)", "|".join(map(utils.ShellQuote, sorted(cmds))))
564 568
        sw.IncIndent()
565 569
        try:
566 570
          CompletionWriter(1, optdef, argdef).WriteTo(sw)
567 571
        finally:
568 572
          sw.DecIndent()
569

  
570 573
        sw.Write(";;")
571 574
      sw.Write("esac")
572 575
  finally:

Also available in: Unified diff