From 4d1b08af6378fdce42cc79b238cdd285e5a8d148 Mon Sep 17 00:00:00 2001 From: Peter Rice Date: Fri, 23 Jan 2026 20:28:50 -0500 Subject: [PATCH] disable qutebrowser entry in choose by default --- CHANGELOG.md | 1 + src/qbpm/choose.py | 21 +++++++++++---------- src/qbpm/config.py | 1 + src/qbpm/config.toml | 3 +++ src/qbpm/main.py | 6 +++--- tests/test_choose.py | 12 +++++++++++- 6 files changed, 30 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12dcbab..85a830f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ # 2.4 + - `qbpm choose`: an entry named `qutebrowser` that launches qutebrowser without a profile will no longer be included by default. Set `qutebrowser_in_choose = true` in `config.toml` to restore it - `config_py_template` is no longer required to be set if `config.toml` exists - if `config_py_template` is set to an empty string, no `config.py` will be generated diff --git a/src/qbpm/choose.py b/src/qbpm/choose.py index d545a98..4787197 100644 --- a/src/qbpm/choose.py +++ b/src/qbpm/choose.py @@ -1,29 +1,30 @@ import subprocess -from pathlib import Path from . import Profile +from .config import Config from .launch import launch_qutebrowser from .log import error from .menus import find_menu def choose_profile( - profile_dir: Path, - menu: str | list[str], - prompt: str, + config: Config, foreground: bool, qb_args: tuple[str, ...], ) -> bool: - dmenu = find_menu(menu) + dmenu = find_menu(config.menu) if not dmenu: return False - real_profiles = {profile.name for profile in profile_dir.iterdir()} + real_profiles = {profile.name for profile in config.profile_directory.iterdir()} if len(real_profiles) == 0: error("no profiles") return False - profiles = [*real_profiles, "qutebrowser"] - command = dmenu.command(sorted(profiles), prompt, " ".join(qb_args)) + profiles = [*real_profiles] + include_qb = config.qutebrowser_in_choose and "qutebrowser" not in real_profiles + if include_qb: + profiles.append("qutebrowser") + command = dmenu.command(sorted(profiles), config.menu_prompt, " ".join(qb_args)) selection_cmd = subprocess.run( command, text=True, @@ -35,10 +36,10 @@ def choose_profile( out = selection_cmd.stdout selection = out.rstrip("\n") - if selection == "qutebrowser" and "qutebrowser" not in real_profiles: + if include_qb and selection == "qutebrowser": return launch_qutebrowser(None, foreground, qb_args) elif selection: - profile = Profile(selection, profile_dir) + profile = Profile(selection, config.profile_directory) return launch_qutebrowser(profile, foreground, qb_args) else: error("no profile selected") diff --git a/src/qbpm/config.py b/src/qbpm/config.py index 9b36933..ddf92fa 100644 --- a/src/qbpm/config.py +++ b/src/qbpm/config.py @@ -32,6 +32,7 @@ config.load_autoconfig() ) menu: str | list[str] = field(default_factory=list) menu_prompt: str = "qutebrowser" + qutebrowser_in_choose: bool = False @classmethod def load(cls, config_file: Path | None) -> "Config": diff --git a/src/qbpm/config.toml b/src/qbpm/config.toml index e58cd8d..5c99fa7 100644 --- a/src/qbpm/config.toml +++ b/src/qbpm/config.toml @@ -44,3 +44,6 @@ config.load_autoconfig() # menu_prompt = "qbpm" # menu_prompt = "profiles" # menu_prompt = "qutebrowser {qb_args}" + +# include a `qutebrowser` entry in `qbpm choose` that starts qutebrowser without a profile +# qutebrowser_in_choose = false diff --git a/src/qbpm/main.py b/src/qbpm/main.py index 5d06ace..dca8424 100644 --- a/src/qbpm/main.py +++ b/src/qbpm/main.py @@ -242,11 +242,11 @@ def choose( All QB_ARGS are passed on to qutebrowser. """ config = context.load_config() + if menu: + config.menu = menu exit_with( choose_profile( - config.profile_directory, - menu or config.menu, - config.menu_prompt, + config, foreground, qb_args, ) diff --git a/tests/test_choose.py b/tests/test_choose.py index ec3a60c..827bfa0 100644 --- a/tests/test_choose.py +++ b/tests/test_choose.py @@ -2,6 +2,7 @@ from os import environ from pathlib import Path from qbpm.choose import choose_profile, find_menu +from qbpm.config import Config from . import no_homedir_fixture # noqa: F401 @@ -29,7 +30,16 @@ def test_choose(tmp_path: Path): profile_dir.mkdir() (profile_dir / "p1").mkdir() (profile_dir / "p2").mkdir() - assert choose_profile(profile_dir, str(menu), "", False, ()) + config = Config(profile_directory=profile_dir, menu=str(menu), menu_prompt="") + assert choose_profile(config, False, ()) + assert log.read_text().startswith( + f"""p1 +p2 +qutebrowser -B {profile_dir / "p1"}""" + ) + log.write_text("") + config.qutebrowser_in_choose = True + assert choose_profile(config, False, ()) assert log.read_text().startswith( f"""p1 p2 -- 2.51.2