Пример #1
0
def refresh():
    """Write the shell declare variable statements to stdout."""
    atexit.register(close_stdio)
    signal.signal(signal.SIGPIPE, signal.SIG_DFL)
    args = sys.argv[1:]
    if len(args) >= 2:
        abort(USAGE + 'dtags: too many arguments')
    if len(args) == 1:
        shell_name = args[0]
        config = SUPPORTED_SHELLS.get(shell_name)
        if config is None:
            abort('dtags: unsupported shell: ' + style.bad(shell_name))
    else:
        shell_path = os.environ.get('SHELL')
        if shell_path is None:
            abort('dtags: undefined environment variable: ' +
                  style.bad('SHELL'))
        shell_name = None
        for supported_shell_name in SUPPORTED_SHELLS:
            if supported_shell_name in shell_path:
                shell_name = supported_shell_name
        config = SUPPORTED_SHELLS.get(shell_name)
        if config is None:
            abort('dtags: unsupported shell: ' + style.bad(shell_path))

    assign_string = 'set -g {} "{}"' if shell_name == 'fish' else '{}="{}"'
    mapping, _ = load_mapping()
    print('\n'.join(
        assign_string.format(tag.replace('-', '_'), paths.pop())
        for tag, paths in mapping.items()
        if len(paths) == 1 and
        tag.replace('-', '_') not in os.environ and
        not get_invalid_tag_chars(tag)
    ))
Пример #2
0
def activate():
    """Write the shell runtime configuration to stdout."""
    atexit.register(close_stdio)
    signal.signal(signal.SIGPIPE, signal.SIG_DFL)
    args = sys.argv[1:]
    if len(args) >= 2:
        abort(USAGE + 'dtags: too many arguments')
    if len(args) == 1:
        shell_name = args[0]
        config = SUPPORTED_SHELLS.get(shell_name)
        if config is None:
            abort('dtags: unsupported shell: ' + style.bad(shell_name))
    else:
        shell_path = os.environ.get('SHELL')
        if shell_path is None:
            abort('dtags: undefined environment variable: ' +
                  style.bad('SHELL'))
        shell_name = None
        for supported_shell_name in SUPPORTED_SHELLS:
            if supported_shell_name in shell_path:
                shell_name = supported_shell_name
        config = SUPPORTED_SHELLS.get(shell_name)
        if config is None:
            abort('dtags: unsupported shell: ' + style.bad(shell_path))
    finish(
        config.format(
            mapping_file=MAPPING_FILE,
            tags_file=TAGS_FILE,
            version=VERSION,
            usage=d.USAGE,
            description=d.DESCRIPTION,
            arg_err_tty=d.ARG_ERR_TTY,
            dest_err_tty=d.DEST_ERR_TTY,
            input_err_tty=d.INPUT_ERR_TTY,
            index_err_tty=d.INDEX_ERR_TTY,
            prompt_tty=d.PROMPT_TTY,
            choice_tty=d.CHOICE_TTY,
            arg_err=d.ARG_ERR,
            dest_err=d.DEST_ERR,
            input_err=d.INPUT_ERR,
            index_err=d.INDEX_ERR,
            prompt=d.PROMPT,
            choice=d.CHOICE,
        ))
Пример #3
0
def activate():
    """Write the shell runtime configuration to stdout."""
    atexit.register(close_stdio)
    signal.signal(signal.SIGPIPE, signal.SIG_DFL)
    args = sys.argv[1:]
    if len(args) >= 2:
        abort(USAGE + 'dtags: too many arguments')
    if len(args) == 1:
        shell_name = args[0]
        config = SUPPORTED_SHELLS.get(shell_name)
        if config is None:
            abort('dtags: unsupported shell: ' + style.bad(shell_name))
    else:
        shell_path = os.environ.get('SHELL')
        if shell_path is None:
            abort('dtags: undefined environment variable: ' +
                  style.bad('SHELL'))
        shell_name = None
        for supported_shell_name in SUPPORTED_SHELLS:
            if supported_shell_name in shell_path:
                shell_name = supported_shell_name
        config = SUPPORTED_SHELLS.get(shell_name)
        if config is None:
            abort('dtags: unsupported shell: ' + style.bad(shell_path))
    finish(config.format(
        mapping_file=MAPPING_FILE,
        tags_file=TAGS_FILE,
        version=VERSION,
        usage=d.USAGE,
        description=d.DESCRIPTION,
        arg_err_tty=d.ARG_ERR_TTY,
        dest_err_tty=d.DEST_ERR_TTY,
        input_err_tty=d.INPUT_ERR_TTY,
        index_err_tty=d.INDEX_ERR_TTY,
        prompt_tty=d.PROMPT_TTY,
        choice_tty=d.CHOICE_TTY,
        arg_err=d.ARG_ERR,
        dest_err=d.DEST_ERR,
        input_err=d.INPUT_ERR,
        index_err=d.INDEX_ERR,
        prompt=d.PROMPT,
        choice=d.CHOICE,
    ))
Пример #4
0
def _shell(args):
    """Write the shell runtime configuration to stdout."""
    if len(args) >= 2:
        abort(USAGE + 'Too many arguments')
    if len(args) == 1:
        shell_name = args[0]
        config = SUPPORTED_SHELLS.get(shell_name)
        if config is None:
            abort('Unsupported shell: ' + style.bad(shell_name))
    else:
        shell_path = os.environ.get('SHELL')
        if shell_path is None:
            abort('Undefined environment variable: ' + style.bad('SHELL'))
        shell_name = None
        for supported_shell_name in SUPPORTED_SHELLS:
            if supported_shell_name in shell_path:
                shell_name = supported_shell_name
        config = SUPPORTED_SHELLS.get(shell_name)
        if config is None:
            abort('Unsupported shell: ' + style.bad(shell_path))
    finish(config.format(
        mapping_file=MAPPING_FILE,
        tags_file=TAGS_FILE,
        version=VERSION,
        usage=directory.USAGE,
        description=directory.DESCRIPTION,
        goto_msg_tty=directory.GOTO_MSG_TTY,
        arg_err_tty=directory.ARG_ERR_TTY,
        dest_err_tty=directory.DEST_ERR_TTY,
        input_err_tty=directory.INPUT_ERR_TTY,
        index_err_tty=directory.INDEX_ERR_TTY,
        prompt_tty=directory.PROMPT_TTY,
        choice_tty=directory.CHOICE_TTY,
        goto_msg=directory.GOTO_MSG,
        arg_err=directory.ARG_ERR,
        dest_err=directory.DEST_ERR,
        input_err=directory.INPUT_ERR,
        index_err=directory.INDEX_ERR,
        prompt=directory.PROMPT,
        choice=directory.CHOICE,
    ))