#!/usr/bin/env python3 import subprocess import sys import shutil import urllib.parse DMENU_OPTS = ["-i", "-fn", "DepartureMono:size=10", "-nb", "#151515", "-nf", "#bbbbbb", "-sb", "#2a1f4d", "-sf", "#eeeeee"] BROWSER = "mullvad-browser-bin" NOTIFIER = "notify-send" CHOICES = [ "Startpage", "URL", "Incognito URL", "YouTube", "Github", "Codeberg", "coasteen.github.io", "IPLeak", "Safebooru", "Wikipedia" ] def notify(title, message): subprocess.run([NOTIFIER, title, message], stderr=subprocess.DEVNULL) def run_dmenu(prompt, options=None): cmd = ["dmenu", *DMENU_OPTS, "-p", prompt] stdin = None if options: stdin = "\n".join(options) proc = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, text=True) out, _ = proc.communicate(stdin) return out.strip() def get_input(prompt, prefix=""): text = run_dmenu(prompt) if not text: notify("Error", "No input provided") sys.exit(1) return prefix + urllib.parse.quote_plus(text) def open_url(url): try: subprocess.Popen([BROWSER, url]) except: notify("Error", f"Failed to open browser: {url}") sys.exit(1) def main(): choice = run_dmenu("Where to?", CHOICES) if not choice: notify("Error", "No selection made") sys.exit(1) if choice == "Github": open_url(get_input("Username & repo:", "https://github.com/")) elif choice == "Codeberg": open_url(get_input("Username & repo:", "https://codeberg.org/")) elif choice == "IPLeak": open_url("https://ipleak.net") elif choice == "Startpage": open_url("https://www.startpage.com/do/search?q=" + get_input("Search Startpage:")) elif choice == "Wikipedia": open_url("https://en.wikipedia.org/wiki/Special:Search?search=" + get_input("Search Wikipedia:")) elif choice == "URL": url = run_dmenu("Enter URL:") if not url: notify("Error", "No URL entered") sys.exit(1) if not url.startswith("http"): url = "https://" + url open_url(url) elif choice == "Incognito URL": url = run_dmenu("Enter incognito URL:") if not url: notify("Error", "No URL entered") sys.exit(1) if not url.startswith("http"): url = "https://" + url subprocess.Popen(["brave-bin", "--incognito", url]) elif choice == "YouTube": open_url("https://youtube.com/results?search_query=" + get_input("Search YouTube:")) elif choice == "Safebooru": open_url("https://safebooru.org/index.php?page=post&s=list&tags=" + get_input("Search Safebooru:")) elif choice == "coasteen.github.io": open_url("https://coasteen.github.io/www/") else: notify("Error", f"Invalid selection: {choice}") sys.exit(1) if __name__ == "__main__": for cmd in ["dmenu", BROWSER]: if shutil.which(cmd) is None: print(f"Error: Required command '{cmd}' not found", file=sys.stderr) sys.exit(1) main()