1import platform
2import subprocess
3import sys
4from pathlib import Path
5from shutil import which
6from sys import exit, stderr
7from typing import Optional
8
9from xdg import BaseDirectory # type: ignore
10
11
12def error(msg: str) -> None:
13 print(f"Error: {msg}", file=stderr)
14
15
16def user_data_dir() -> Path:
17 if platform.system() == "Linux":
18 return Path(BaseDirectory.xdg_data_home) / "qutebrowser"
19 if platform.system() == "Darwin":
20 return Path.home() / "Library" / "Application Support" / "qutebrowser"
21 error("This operation is only implemented for linux and macOS.")
22 print(
23 "If you're interested in adding support for another OS, send a PR "
24 "to github.com/pvsr/qbpm adding the location of qutebrowser data such "
25 "as history.sqlite on your OS to user_data_dir() in qpm/utils.py.",
26 file=stderr,
27 )
28 exit(1)
29
30
31def user_config_dir() -> Path:
32 return Path(BaseDirectory.xdg_config_home) / "qutebrowser"
33
34
35def get_default_menu() -> Optional[str]:
36 if sys.platform == "darwin":
37 return "applescript"
38 for menu_cmd in ["rofi", "dmenu"]:
39 if which(menu_cmd) is not None:
40 return menu_cmd
41 return None