Skip to content

Commit 857331b

Browse files
committed
fall back to fzf
1 parent f2d028b commit 857331b

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

qbpm/operations.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from . import profiles
1212
from .profiles import Profile
13-
from .utils import AUTO_MENUS, error, get_default_menu, user_data_dir
13+
from .utils import AUTO_MENUS, error, installed_menus, user_data_dir
1414

1515

1616
def from_session(
@@ -85,7 +85,7 @@ def list_(args: argparse.Namespace) -> bool:
8585

8686

8787
def choose(args: argparse.Namespace) -> bool:
88-
menu = args.menu or get_default_menu()
88+
menu = args.menu or next(installed_menus())
8989
if not menu:
9090
error(f"No menu program found, please install one of: {AUTO_MENUS}")
9191
return False
@@ -137,9 +137,9 @@ def menu_command(
137137
command = f"{menu} -dmenu -no-custom {prompt} -mesg {arg_string}"
138138
elif program == "wofi":
139139
command = f"{menu} --dmenu {prompt}"
140-
elif program in ["dmenu", "dmenu-wl"]:
140+
elif program.startswith("dmenu"):
141141
command = f"{menu} {prompt}"
142-
elif program == "fzf":
142+
elif program.startswith("fzf"):
143143
command = f"{menu} --prompt 'qutebrowser '"
144144
elif program == "fuzzel":
145145
command = f"{menu} -d"

qbpm/utils.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import platform
2+
from collections.abc import Generator
23
from os import environ
34
from pathlib import Path
45
from shutil import which
@@ -36,23 +37,20 @@ def user_config_dir() -> Path:
3637
return Path(BaseDirectory.xdg_config_home) / "qutebrowser"
3738

3839

39-
def get_default_menu() -> Optional[str]:
40+
def installed_menus() -> Generator[str, None, None]:
4041
if platform.system() == "Darwin":
41-
return "applescript"
42+
yield "applescript"
4243
if environ.get("WAYLAND_DISPLAY"):
4344
for menu_cmd in WAYLAND_MENUS:
4445
if which(menu_cmd) is not None:
45-
return menu_cmd
46-
elif environ.get("DISPLAY"):
46+
yield menu_cmd
47+
if environ.get("DISPLAY"):
4748
for menu_cmd in X11_MENUS:
4849
if which(menu_cmd) is not None:
49-
return menu_cmd
50-
else:
51-
# TODO can we detect whether we're in a term so we can run fzf?
52-
error(
53-
"Neither $DISPLAY nor $WAYLAND_DISPLAY are set,"
54-
+ " cannot launch a graphical menu."
55-
+ " Consider passing `--menu fzf`"
56-
)
57-
exit(1)
58-
return None
50+
yield menu_cmd
51+
if environ.get("TMUX") and which("fzf-tmux") is not None:
52+
yield "fzf-tmux"
53+
# if there's no display and fzf is installed we're probably(?) in a term
54+
if which("fzf") is not None:
55+
print("no graphical launchers found, trying fzf", file=stderr)
56+
yield "fzf"

0 commit comments

Comments
 (0)