mirror of
https://git.sr.ht/~coasteen/dotfiles
synced 2025-11-04 14:47:38 +01:00
suicide
This commit is contained in:
parent
3b0c7ebb8a
commit
b98ba405fa
8 changed files with 111 additions and 92 deletions
|
|
@ -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 int user_bh = 0; /* add an defined amount of pixels to the bar height */
|
||||||
|
|
||||||
static const char *fonts[] = {
|
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 *prompt = NULL; /* -p option; prompt to the left of input field */
|
||||||
static const char *colors[SchemeLast][2] = {
|
static const char *colors[SchemeLast][2] = {
|
||||||
/* fg bg */
|
/* fg bg */
|
||||||
[SchemeNorm] = { "#cccccc", "#000000" }, // normal: grey text on black
|
[SchemeNorm] = { "#a8dcee", "#000000" }, // text #a8dcee on black background
|
||||||
[SchemeSel] = { "#000000", "#ffffff" }, // selected: black text on white
|
[SchemeSel] = { "#000000", "#a8dcee" }, // text black on #a8dcee background
|
||||||
[SchemeOut] = { "#000000", "#00ffff" }, // optional: match previous Out
|
[SchemeOut] = { "#000000", "#a8dcee" }, // text black on #a8dcee background (optional)
|
||||||
};
|
};
|
||||||
/* -l option; if nonzero, dmenu uses vertical list with given number of lines */
|
/* -l option; if nonzero, dmenu uses vertical list with given number of lines */
|
||||||
static unsigned int lines = 0;
|
static unsigned int lines = 0;
|
||||||
|
|
|
||||||
BIN
dmenu/dmenu
Executable file
BIN
dmenu/dmenu
Executable file
Binary file not shown.
BIN
dmenu/dmenu.o
Normal file
BIN
dmenu/dmenu.o
Normal file
Binary file not shown.
BIN
dmenu/drw.o
Normal file
BIN
dmenu/drw.o
Normal file
Binary file not shown.
BIN
dmenu/stest
Executable file
BIN
dmenu/stest
Executable file
Binary file not shown.
BIN
dmenu/stest.o
Normal file
BIN
dmenu/stest.o
Normal file
Binary file not shown.
BIN
dmenu/util.o
Normal file
BIN
dmenu/util.o
Normal file
Binary file not shown.
|
|
@ -1,99 +1,118 @@
|
||||||
#!/usr/bin/env python3
|
#!/bin/sh
|
||||||
import subprocess
|
|
||||||
import sys
|
|
||||||
import shutil
|
|
||||||
import urllib.parse
|
|
||||||
import os
|
|
||||||
|
|
||||||
DMENU_OPTS = ["-i", "-fn", "monospace:size=12", "-nb", "#151515", "-nf", "#bbbbbb", "-sb", "#005577", "-sf", "#eeeeee"]
|
WMENU="wmenu"
|
||||||
BROWSER = "firefox"
|
DMENU="dmenu"
|
||||||
NOTIFIER = "notify-send"
|
BROWSER="firefox-bin"
|
||||||
|
NOTIFY="notify-send"
|
||||||
|
|
||||||
CHOICES = [
|
CHOICES="Paulgo
|
||||||
"Paulgo", "URL", "Incognito URL", "YouTube", "Codeberg", "Tildegit", "IPLeak", "Safebooru", "Wikipedia"
|
URL
|
||||||
]
|
Incognito URL
|
||||||
|
YouTube
|
||||||
|
Codeberg
|
||||||
|
Tildegit
|
||||||
|
IPLeak
|
||||||
|
Safebooru
|
||||||
|
Wikipedia"
|
||||||
|
|
||||||
def notify(title, message):
|
notify() {
|
||||||
subprocess.run([NOTIFIER, title, message], stderr=subprocess.DEVNULL)
|
"$NOTIFY" "$1" "$2" 2>/dev/null
|
||||||
|
}
|
||||||
|
|
||||||
def run_dmenu(prompt, options=None):
|
run_wmenu() {
|
||||||
cmd = ["dmenu", *DMENU_OPTS, "-p", prompt]
|
printf '%s\n' "$1" | $WMENU -p "$2"
|
||||||
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()
|
|
||||||
|
|
||||||
def get_input(prompt, prefix=""):
|
run_dmenu() {
|
||||||
text = run_dmenu(prompt)
|
printf '' | $DMENU -p "$1"
|
||||||
if not text:
|
}
|
||||||
notify("Error", "No input provided")
|
|
||||||
sys.exit(1)
|
|
||||||
return prefix + urllib.parse.quote_plus(text)
|
|
||||||
|
|
||||||
def is_browser_running():
|
urlencode() {
|
||||||
try:
|
python3 -c "import sys, urllib.parse as ul; print(ul.quote_plus(sys.argv[1]))" "$1"
|
||||||
proc = subprocess.Popen(["pgrep", "-f", BROWSER], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
|
}
|
||||||
proc.communicate()
|
|
||||||
return proc.returncode == 0
|
|
||||||
except:
|
|
||||||
return False
|
|
||||||
|
|
||||||
def open_url(url):
|
open_url() {
|
||||||
try:
|
url="$1"
|
||||||
if is_browser_running():
|
if pgrep -x "$BROWSER" >/dev/null; then
|
||||||
subprocess.Popen([BROWSER, ":open", "-t", url])
|
"$BROWSER" --new-tab "$url" &
|
||||||
else:
|
else
|
||||||
subprocess.Popen([BROWSER, url])
|
"$BROWSER" "$url" &
|
||||||
except Exception as e:
|
fi
|
||||||
notify("Error", f"Failed to open browser: {url}\n{e}")
|
}
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
def search_with_paulgio(query):
|
main() {
|
||||||
return f"https://paulgo.io/search?q={urllib.parse.quote_plus(query)}"
|
choice=$(run_wmenu "$CHOICES" "Where to?")
|
||||||
|
[ -z "$choice" ] && notify "Error" "No selection made" && exit 1
|
||||||
|
|
||||||
def main():
|
case "$choice" in
|
||||||
choice = run_dmenu("Where to?", CHOICES)
|
Codeberg)
|
||||||
if not choice:
|
repo=$(run_dmenu "Username & repo (user/repo):")
|
||||||
notify("Error", "No selection made")
|
[ -z "$repo" ] && notify "Error" "No input" && exit 1
|
||||||
sys.exit(1)
|
open_url "https://codeberg.org/$repo"
|
||||||
elif choice == "Codeberg":
|
;;
|
||||||
open_url(get_input("Username & repo:", "https://codeberg.org/"))
|
Tildegit)
|
||||||
elif choice == "Tildegit":
|
repo=$(run_dmenu "Username & repo (user/repo):")
|
||||||
open_url(get_input("Username & repo:", "https://tildegit.org/"))
|
[ -z "$repo" ] && notify "Error" "No input" && exit 1
|
||||||
elif choice == "IPLeak":
|
open_url "https://tildegit.org/$repo"
|
||||||
open_url("https://ipleak.net")
|
;;
|
||||||
elif choice == "Paulgo":
|
IPLeak)
|
||||||
open_url(search_with_paulgio(get_input("Search Paulgo:")))
|
open_url "https://ipleak.net"
|
||||||
elif choice == "Wikipedia":
|
;;
|
||||||
open_url("https://en.wikipedia.org/wiki/Special:Search?search=" + get_input("Search Wikipedia:"))
|
Paulgo)
|
||||||
elif choice == "URL":
|
query=$(run_dmenu "Search Paulgo:")
|
||||||
url = run_dmenu("Enter URL:")
|
[ -z "$query" ] && notify "Error" "No input" && exit 1
|
||||||
if not url:
|
qenc=$(urlencode "$query")
|
||||||
notify("Error", "No URL entered")
|
open_url "https://paulgo.io/search?q=$qenc"
|
||||||
sys.exit(1)
|
;;
|
||||||
if not url.startswith("http"):
|
Wikipedia)
|
||||||
url = "https://" + url
|
query=$(run_dmenu "Search Wikipedia:")
|
||||||
open_url(url)
|
[ -z "$query" ] && notify "Error" "No input" && exit 1
|
||||||
elif choice == "Incognito URL":
|
qenc=$(urlencode "$query")
|
||||||
url = run_dmenu("Enter incognito URL:")
|
open_url "https://en.wikipedia.org/wiki/Special:Search?search=$qenc"
|
||||||
if not url:
|
;;
|
||||||
notify("Error", "No URL entered")
|
URL)
|
||||||
sys.exit(1)
|
url=$(run_dmenu "Enter URL:")
|
||||||
if not url.startswith("http"):
|
[ -z "$url" ] && notify "Error" "No URL entered" && exit 1
|
||||||
url = "https://" + url
|
case "$url" in
|
||||||
subprocess.Popen(["brave-bin", "--incognito", url])
|
http*) ;;
|
||||||
elif choice == "YouTube":
|
*) url="https://$url" ;;
|
||||||
open_url("https://youtube.com/results?search_query=" + get_input("Search YouTube:"))
|
esac
|
||||||
elif choice == "Safebooru":
|
open_url "$url"
|
||||||
open_url("https://safebooru.org/index.php?page=post&s=list&tags=" + get_input("Search Safebooru:"))
|
;;
|
||||||
else:
|
"Incognito URL")
|
||||||
notify("Error", f"Invalid selection: {choice}")
|
url=$(run_dmenu "Enter incognito URL:")
|
||||||
sys.exit(1)
|
[ -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 "$WMENU" "$DMENU" "$BROWSER" "$NOTIFY"; do
|
||||||
for cmd in ["dmenu", BROWSER]:
|
if ! command -v "$cmd" >/dev/null 2>&1; then
|
||||||
if shutil.which(cmd) is None:
|
echo "Error: required command '$cmd' not found" >&2
|
||||||
print(f"Error: Required command '{cmd}' not found", file=sys.stderr)
|
exit 1
|
||||||
sys.exit(1)
|
fi
|
||||||
main()
|
done
|
||||||
|
|
||||||
|
main
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue