Raise `IndexError` if IN_BATCH0 - IN_BATCHx is not used sequentially in `cmd_array`

        :returns: (IN_BATCH0's cmdidx, IN_BATCH1's cmdidx, ...)
            $ cat a.txt IN_BATCH1 IN_BATCH0 b.txt c.txt IN_BATCH2 => (3, 2, 5)

def _in_batches_cmdidx(cmd_array):
        """Raise `IndexError` if IN_BATCH0 - IN_BATCHx is not used sequentially in `cmd_array`

        :returns: (IN_BATCH0's cmdidx, IN_BATCH1's cmdidx, ...)
            $ cat a.txt IN_BATCH1 IN_BATCH0 b.txt c.txt IN_BATCH2 => (3, 2, 5)
        """
        in_batches_cmdidx_dict = {}
        for cmdidx, tok in enumerate(cmd_array):
            mat = BatchCommand.in_batches_pat.match(tok)
            if mat:
                batch_idx = int(mat.group(1))
                if batch_idx in in_batches_cmdidx_dict:
                    raise IndexError(
                        'IN_BATCH%d is used multiple times in command below, while IN_BATCH0 - IN_BATCH%d must be used:%s$ %s' %
                        (batch_idx, len(in_batches_cmdidx_dict) - 1, os.linesep, list2cmdline(cmd_array)))
                in_batches_cmdidx_dict[batch_idx] = cmdidx

        in_batches_cmdidx = []
        for batch_idx in range(len(in_batches_cmdidx_dict)):
            try:
                cmdidx = in_batches_cmdidx_dict[batch_idx]
                in_batches_cmdidx.append(cmdidx)
            except KeyError:
                raise IndexError('IN_BATCH%d is not found in command below, while IN_BATCH0 - IN_BATCH%d must be used:%s$ %s' %
                                 (batch_idx, len(in_batches_cmdidx_dict) - 1, os.linesep, list2cmdline(cmd_array)))

        return tuple(in_batches_cmdidx)