Skip to content

Commit 5e091f8

Browse files
committed
split --menu input as shell string
1 parent 6cc78a4 commit 5e091f8

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/qbpm/menus.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import platform
2+
import shlex
23
import sys
34
from collections.abc import Iterator
45
from dataclasses import dataclass, replace
@@ -57,13 +58,13 @@ def find_menu(menu: str | None) -> Dmenu | ApplescriptMenu | None:
5758

5859

5960
def custom_dmenu(command: str) -> Dmenu:
60-
split = command.split(" ", maxsplit=1)
61+
split = shlex.split(command)
6162
if len(split) == 1 or not split[1]:
6263
name = Path(command).name
6364
for menu in supported_menus():
6465
if isinstance(menu, Dmenu) and menu.name == name:
6566
return menu if menu.name == command else replace(menu, name=command)
66-
return Dmenu(split[0], split[1] if len(split) == 2 else "")
67+
return Dmenu(split[0], " ".join(split[1::]))
6768

6869

6970
def supported_menus() -> Iterator[Dmenu | ApplescriptMenu]:

tests/test_choose.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ def test_invalid_custom_menu():
6464
assert find_menu("fake_command") is None
6565

6666

67+
def test_custom_menu_space_in_name(tmp_path: Path):
68+
write_script(tmp_path / "bin", name="my menu")
69+
environ["PATH"] = str(tmp_path / "bin")
70+
environ["DISPLAY"] = ":1"
71+
dmenu = find_menu("my\\ menu")
72+
assert dmenu is not None
73+
assert dmenu.installed()
74+
75+
6776
def test_custom_menu_default_args(tmp_path: Path):
6877
menu = write_script(tmp_path / "bin", name="rofi")
6978
environ["PATH"] = str(tmp_path / "bin")

0 commit comments

Comments
 (0)