diff --git a/src/qbpm/menus.py b/src/qbpm/menus.py index 741f26a..f7de843 100644 --- a/src/qbpm/menus.py +++ b/src/qbpm/menus.py @@ -1,4 +1,5 @@ import platform +import shlex import sys from collections.abc import Iterator from dataclasses import dataclass, replace @@ -57,13 +58,13 @@ def find_menu(menu: str | None) -> Dmenu | ApplescriptMenu | None: def custom_dmenu(command: str) -> Dmenu: - split = command.split(" ", maxsplit=1) + split = shlex.split(command) if len(split) == 1 or not split[1]: name = Path(command).name for menu in supported_menus(): if isinstance(menu, Dmenu) and menu.name == name: return menu if menu.name == command else replace(menu, name=command) - return Dmenu(split[0], split[1] if len(split) == 2 else "") + return Dmenu(split[0], " ".join(split[1::])) def supported_menus() -> Iterator[Dmenu | ApplescriptMenu]: diff --git a/tests/test_choose.py b/tests/test_choose.py index 36bdf3d..3eb5042 100644 --- a/tests/test_choose.py +++ b/tests/test_choose.py @@ -64,6 +64,15 @@ def test_invalid_custom_menu(): assert find_menu("fake_command") is None +def test_custom_menu_space_in_name(tmp_path: Path): + write_script(tmp_path / "bin", name="my menu") + environ["PATH"] = str(tmp_path / "bin") + environ["DISPLAY"] = ":1" + dmenu = find_menu("my\\ menu") + assert dmenu is not None + assert dmenu.installed() + + def test_custom_menu_default_args(tmp_path: Path): menu = write_script(tmp_path / "bin", name="rofi") environ["PATH"] = str(tmp_path / "bin")