示例#1
0
def complete_skipper(command_context: CommandContext):
    """
    Skip over several tokens (e.g., sudo) and complete based on the rest of the command.
    """

    # Contextual completers don't need us to skip tokens since they get the correct completion context -
    # meaning we only need to skip commands like ``sudo``.
    skip_part_num = 0
    # all the args before the current argument
    for arg in command_context.args[: command_context.arg_index]:
        if arg.value not in SKIP_TOKENS:
            break
        skip_part_num += 1

    if skip_part_num == 0:
        return None

    skipped_command_context = command_context._replace(
        args=command_context.args[skip_part_num:],
        arg_index=command_context.arg_index - skip_part_num,
    )

    if skipped_command_context.arg_index == 0:
        # completing the command after a SKIP_TOKEN
        return complete_command(skipped_command_context)

    completer: Completer = XSH.shell.shell.completer  # type: ignore
    return completer.complete_from_context(CompletionContext(skipped_command_context))
示例#2
0
def complete_skipper(command_context: CommandContext):
    """
    Skip over several tokens (e.g., sudo) and complete based on the rest of the command.

    Contextual completers don't need us to skip tokens since they get the correct completion context -
    meaning we only need to skip commands like ``sudo``.
    """
    skip_part_num = 0
    for skip_part_num, arg in enumerate(
            command_context.args[:command_context.arg_index]):
        # all the args before the current argument
        if arg.value not in SKIP_TOKENS:
            break

    if skip_part_num == 0:
        return None

    skipped_context = CompletionContext(command=command_context._replace(
        args=command_context.args[skip_part_num:],
        arg_index=command_context.arg_index - skip_part_num,
    ))

    completers = builtins.__xonsh__.completers.values()  # type: ignore
    for completer in completers:
        if is_contextual_completer(completer):
            results = completer(skipped_context)
            if results:
                return results
    return None