~pvsr/qpm

b27ba30481ff627c38419814f1a0752361b86cf7 — Peter Rice a month ago 9dfa29c
pass configured profile-dir to list and choose
2 files changed, 10 insertions(+), 9 deletions(-)

M qpm/main.py
M qpm/operations.py
M qpm/main.py => qpm/main.py +7 -3
@@ 3,9 3,13 @@ from os import environ
from pathlib import Path
from typing import Any, Callable, Optional

from xdg import BaseDirectory  # type: ignore

from qpm import __version__, operations, profiles
from qpm.profiles import Profile

DEFAULT_PROFILE_DIR = Path(BaseDirectory.xdg_data_home) / "qutebrowser-profiles"


def main(mock_args=None) -> None:
    parser = argparse.ArgumentParser(description="qutebrowser profile manager")


@@ 103,7 107,7 @@ def main(mock_args=None) -> None:
    )

    list_ = subparsers.add_parser("list", help="list existing profiles")
    list_.set_defaults(operation=lambda args: operations.list_())
    list_.set_defaults(operation=lambda args: operations.list_(args))

    choose = subparsers.add_parser(
        "choose", help="choose profile using rofi, dmenu, or an applescript dialog"


@@ 130,8 134,8 @@ def main(mock_args=None) -> None:
    raw_args = parser.parse_known_args(mock_args)
    args = raw_args[0]
    args.qb_args = raw_args[1]
    if not args.profile_dir and (env_dir := environ.get("QPM_PROFILE_DIR")):
        args.profile_dir = Path(env_dir)
    if not args.profile_dir:
        args.profile_dir = Path(environ.get("QPM_PROFILE_DIR") or DEFAULT_PROFILE_DIR)
    args.operation(args)



M qpm/operations.py => qpm/operations.py +3 -6
@@ 73,11 73,8 @@ def desktop(profile: Profile):
        error(f"profile {profile.name} not found at {profile.root}")


DEFAULT_PROFILE_DIR = Path(BaseDirectory.xdg_data_home) / "qutebrowser-profiles"


def list_() -> None:
    for profile in sorted(DEFAULT_PROFILE_DIR.iterdir()):
def list_(args: argparse.Namespace) -> None:
    for profile in sorted(args.profile_dir.iterdir()):
        print(profile.name)




@@ 102,7 99,7 @@ def choose(args: argparse.Namespace) -> None:
        return None

    profile_list = "\n".join(
        [profile.name for profile in sorted(DEFAULT_PROFILE_DIR.iterdir())]
        [profile.name for profile in sorted(args.profile_dir.iterdir())]
    )
    if not profile_list:
        error("No existing profiles found, create a profile first with qbpm new")