diff --git a/dmenu/config.h b/dmenu/config.h index de78b06..d79a598 100644 --- a/dmenu/config.h +++ b/dmenu/config.h @@ -6,14 +6,14 @@ static int topbar = 1; /* -b option; if 0, dmenu appears a static const int user_bh = 0; /* add an defined amount of pixels to the bar height */ static const char *fonts[] = { - "monospace:size=13" + "Departure Mono:size=13" }; static const char *prompt = NULL; /* -p option; prompt to the left of input field */ static const char *colors[SchemeLast][2] = { /* fg bg */ - [SchemeNorm] = { "#cccccc", "#000000" }, // normal: grey text on black - [SchemeSel] = { "#000000", "#ffffff" }, // selected: black text on white - [SchemeOut] = { "#000000", "#00ffff" }, // optional: match previous Out + [SchemeNorm] = { "#a8dcee", "#000000" }, // text #a8dcee on black background +[SchemeSel] = { "#000000", "#a8dcee" }, // text black on #a8dcee background +[SchemeOut] = { "#000000", "#a8dcee" }, // text black on #a8dcee background (optional) }; /* -l option; if nonzero, dmenu uses vertical list with given number of lines */ static unsigned int lines = 0; diff --git a/dmenu/dmenu b/dmenu/dmenu new file mode 100755 index 0000000..794fea4 Binary files /dev/null and b/dmenu/dmenu differ diff --git a/dmenu/dmenu.o b/dmenu/dmenu.o new file mode 100644 index 0000000..1e2a4c1 Binary files /dev/null and b/dmenu/dmenu.o differ diff --git a/dmenu/drw.o b/dmenu/drw.o new file mode 100644 index 0000000..69dbfa9 Binary files /dev/null and b/dmenu/drw.o differ diff --git a/dmenu/stest b/dmenu/stest new file mode 100755 index 0000000..344348c Binary files /dev/null and b/dmenu/stest differ diff --git a/dmenu/stest.o b/dmenu/stest.o new file mode 100644 index 0000000..3d5045e Binary files /dev/null and b/dmenu/stest.o differ diff --git a/dmenu/util.o b/dmenu/util.o new file mode 100644 index 0000000..5dd48bf Binary files /dev/null and b/dmenu/util.o differ diff --git a/local/bin/brwmenu b/local/bin/brwmenu index 1d27bb0..11628eb 100755 --- a/local/bin/brwmenu +++ b/local/bin/brwmenu @@ -1,99 +1,118 @@ -#!/usr/bin/env python3 -import subprocess -import sys -import shutil -import urllib.parse -import os +#!/bin/sh -DMENU_OPTS = ["-i", "-fn", "monospace:size=12", "-nb", "#151515", "-nf", "#bbbbbb", "-sb", "#005577", "-sf", "#eeeeee"] -BROWSER = "firefox" -NOTIFIER = "notify-send" +WMENU="wmenu" +DMENU="dmenu" +BROWSER="firefox-bin" +NOTIFY="notify-send" -CHOICES = [ - "Paulgo", "URL", "Incognito URL", "YouTube", "Codeberg", "Tildegit", "IPLeak", "Safebooru", "Wikipedia" -] +CHOICES="Paulgo +URL +Incognito URL +YouTube +Codeberg +Tildegit +IPLeak +Safebooru +Wikipedia" -def notify(title, message): - subprocess.run([NOTIFIER, title, message], stderr=subprocess.DEVNULL) +notify() { + "$NOTIFY" "$1" "$2" 2>/dev/null +} -def run_dmenu(prompt, options=None): - cmd = ["dmenu", *DMENU_OPTS, "-p", prompt] - stdin = "\n".join(options) if options else None - proc = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, text=True) - out, _ = proc.communicate(stdin) - return out.strip() +run_wmenu() { + printf '%s\n' "$1" | $WMENU -p "$2" +} -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) +run_dmenu() { + printf '' | $DMENU -p "$1" +} -def is_browser_running(): - try: - proc = subprocess.Popen(["pgrep", "-f", BROWSER], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL) - proc.communicate() - return proc.returncode == 0 - except: - return False +urlencode() { + python3 -c "import sys, urllib.parse as ul; print(ul.quote_plus(sys.argv[1]))" "$1" +} -def open_url(url): - try: - if is_browser_running(): - subprocess.Popen([BROWSER, ":open", "-t", url]) - else: - subprocess.Popen([BROWSER, url]) - except Exception as e: - notify("Error", f"Failed to open browser: {url}\n{e}") - sys.exit(1) +open_url() { + url="$1" + if pgrep -x "$BROWSER" >/dev/null; then + "$BROWSER" --new-tab "$url" & + else + "$BROWSER" "$url" & + fi +} -def search_with_paulgio(query): - return f"https://paulgo.io/search?q={urllib.parse.quote_plus(query)}" +main() { + choice=$(run_wmenu "$CHOICES" "Where to?") + [ -z "$choice" ] && notify "Error" "No selection made" && exit 1 -def main(): - choice = run_dmenu("Where to?", CHOICES) - if not choice: - notify("Error", "No selection made") - sys.exit(1) - elif choice == "Codeberg": - open_url(get_input("Username & repo:", "https://codeberg.org/")) - elif choice == "Tildegit": - open_url(get_input("Username & repo:", "https://tildegit.org/")) - elif choice == "IPLeak": - open_url("https://ipleak.net") - elif choice == "Paulgo": - open_url(search_with_paulgio(get_input("Search Paulgo:"))) - 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:")) - else: - notify("Error", f"Invalid selection: {choice}") - sys.exit(1) + case "$choice" in + Codeberg) + repo=$(run_dmenu "Username & repo (user/repo):") + [ -z "$repo" ] && notify "Error" "No input" && exit 1 + open_url "https://codeberg.org/$repo" + ;; + Tildegit) + repo=$(run_dmenu "Username & repo (user/repo):") + [ -z "$repo" ] && notify "Error" "No input" && exit 1 + open_url "https://tildegit.org/$repo" + ;; + IPLeak) + open_url "https://ipleak.net" + ;; + Paulgo) + query=$(run_dmenu "Search Paulgo:") + [ -z "$query" ] && notify "Error" "No input" && exit 1 + qenc=$(urlencode "$query") + open_url "https://paulgo.io/search?q=$qenc" + ;; + Wikipedia) + query=$(run_dmenu "Search Wikipedia:") + [ -z "$query" ] && notify "Error" "No input" && exit 1 + qenc=$(urlencode "$query") + open_url "https://en.wikipedia.org/wiki/Special:Search?search=$qenc" + ;; + URL) + url=$(run_dmenu "Enter URL:") + [ -z "$url" ] && notify "Error" "No URL entered" && exit 1 + case "$url" in + http*) ;; + *) url="https://$url" ;; + esac + open_url "$url" + ;; + "Incognito URL") + url=$(run_dmenu "Enter incognito URL:") + [ -z "$url" ] && notify "Error" "No URL entered" && exit 1 + case "$url" in + http*) ;; + *) url="https://$url" ;; + esac + "$BROWSER" --private-window "$url" & + ;; + YouTube) + query=$(run_dmenu "Search YouTube:") + [ -z "$query" ] && notify "Error" "No input" && exit 1 + qenc=$(urlencode "$query") + open_url "https://youtube.com/results?search_query=$qenc" + ;; + Safebooru) + query=$(run_dmenu "Search Safebooru:") + [ -z "$query" ] && notify "Error" "No input" && exit 1 + qenc=$(urlencode "$query") + open_url "https://safebooru.org/index.php?page=post&s=list&tags=$qenc" + ;; + *) + notify "Error" "Invalid selection: $choice" + exit 1 + ;; + esac +} -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() +for cmd in "$WMENU" "$DMENU" "$BROWSER" "$NOTIFY"; do + if ! command -v "$cmd" >/dev/null 2>&1; then + echo "Error: required command '$cmd' not found" >&2 + exit 1 + fi +done + +main