def launch_editor(ctx, file):
    editor = os.environ.get("PW_EDITOR")
    if not editor:
        click.echo("error: no editor set in PW_EDITOR environment variables")
        ctx.exit(1)
    if not os.path.exists(file):
        click.echo("error: password store not found at '%s'" % file, err=True)
        ctx.exit(1)
    is_encrypted = _gpg.is_encrypted(file)
    if is_encrypted:
        original = _gpg.decrypt(file)
    else:
        original = open(file, "rb").read()
    if is_encrypted:
        recipient = os.environ.get("PW_GPG_RECIPIENT")
        if not recipient:
            click.echo(
                "error: no recipient set in PW_GPG_RECIPIENT environment variables"
            )
            ctx.exit(1)
    ext = _gpg.unencrypted_ext(file)
    modified = click.edit(
        original.decode("utf-8"), editor=editor, require_save=True, extension=ext
    )
    if modified is None:
        click.echo("not modified")
        return
    modified = modified.encode("utf-8")
    if not is_encrypted:
        with open(file, "wb") as fp:
            fp.write(modified)
        return
    _gpg.encrypt(recipient=recipient, dest_path=file, content=modified)