示例#1
0
文件: cli.py 项目: Leopardob/be
def activate():
    """Enter into an environment with support for tab-completion

    This command drops you into a subshell, similar to the one
    generated via `be in ...`, except no topic is present and
    instead it enables tab-completion for supported shells.

    See documentation for further information.
    https://github.com/mottosso/be/wiki/cli

    """

    parent = lib.parent()
    cmd = lib.cmd(parent)

    # Store reference to calling shell
    context = lib.context()
    context["BE_SHELL"] = parent

    if lib.platform() == "unix":
        context["BE_TABCOMPLETION"] = os.path.join(
            os.path.dirname(__file__), "_autocomplete.sh").replace("\\", "/")

    context.pop("BE_ACTIVE", None)

    sys.exit(subprocess.call(cmd, env=context))
示例#2
0
文件: _extern.py 项目: Leopardob/be
def write_aliases(aliases, tempdir):
    """Write aliases to temporary directory

    Arguments:
        aliases (dict): {name: value} dict of aliases
        tempdir (str): Absolute path to where aliases will be stored

    """

    platform = lib.platform()
    if platform == "unix":
        home_alias = "cd $BE_DEVELOPMENTDIR"
    else:
        home_alias = "cd %BE_DEVELOPMENTDIR%"

    aliases["home"] = home_alias

    tempdir = os.path.join(tempdir, "aliases")
    os.makedirs(tempdir)

    for alias, cmd in aliases.iteritems():
        path = os.path.join(tempdir, alias)

        if platform == "windows":
            path += ".bat"

        with open(path, "w") as f:
            f.write(cmd)

        if platform == "unix":
            # Make executable on unix systems
            st = os.stat(path)
            os.chmod(path, st.st_mode | stat.S_IXUSR
                     | stat.S_IXGRP | stat.S_IXOTH)

    return tempdir