dotfiles/local/bin/brwmenu

100 lines
3 KiB
Text
Raw Normal View History

2025-07-11 11:19:32 +03:30
#!/bin/sh
#inspired by 'firemenu' by <swindlesmccoop> on github
# BRWMENU:
set -e
2025-07-21 12:57:44 +03:30
DMENU_OPTS="-i -fn DepartureMono:size=10 -nb #151515 -nf #bbbbbb -sb #884757 -sf #eeeeee"
BROWSER="mullvad-browser-bin"
2025-07-11 11:19:32 +03:30
SWALLOW=""
NOTIFIER="notify-send"
for cmd in dmenu "$BROWSER"; do
if ! command -v "$cmd" >/dev/null 2>&1; then
echo "Error: Required command '$cmd' not found" >&2
exit 1
fi
done
2025-07-21 12:57:44 +03:30
CHOICES="Startpage\nURL\nIncognito URL\nYouTube\nGithub\nCodeberg\ncoasteen.github.io\nIPLeak\nSafebooru\nWikipedia"
2025-07-11 11:19:32 +03:30
PROMPT="Where to?"
open_url() {
if [ -z "$1" ]; then
$NOTIFIER "Error" "No URL specified" 2>/dev/null || echo "Error: No URL specified" >&2
exit 1
fi
2025-07-21 12:57:44 +03:30
if ! $SWALLOW $BROWSER "$1" >/dev/null 2>&1; then
2025-07-11 11:19:32 +03:30
$NOTIFIER "Error" "Failed to open browser with URL: $1" 2>/dev/null || \
echo "Error: Failed to open browser with URL: $1" >&2
exit 1
fi
}
get_input() {
prompt="$1"
prefix="$2"
input=$(printf '' | dmenu $DMENU_OPTS -p "$prompt" 2>/dev/null)
2025-07-21 12:57:44 +03:30
2025-07-11 11:19:32 +03:30
if [ -z "$input" ]; then
$NOTIFIER "Error" "No input provided" 2>/dev/null || echo "Error: No input provided" >&2
exit 1
fi
2025-07-21 12:57:44 +03:30
2025-07-11 11:19:32 +03:30
input=$(printf "%s" "$input" | sed 's/ /%20/g')
echo "${prefix}${input}"
}
CHOICE=$(printf "$CHOICES" | dmenu $DMENU_OPTS -p "$PROMPT" 2>/dev/null)
case "$CHOICE" in
Github)
url=$(get_input "Username & repo:" "https://github.com/")
open_url "$url"
;;
Codeberg)
url=$(get_input "Username & repo:" "https://codeberg.org/")
open_url "$url"
;;
IPLeak)
open_url "https://ipleak.net"
;;
2025-07-21 12:57:44 +03:30
Startpage)
query=$(get_input "Search Startpage:" "")
open_url "https://www.startpage.com/do/search?q="
2025-07-11 11:19:32 +03:30
;;
2025-07-21 12:57:44 +03:30
Wikipedia)
query=$(get_input "Search Wikipedia:" "")
open_url "https://en.wikipedia.org/wiki/Special:Search?search=$query"
2025-07-11 11:19:32 +03:30
;;
URL)
url=$(get_input "Enter URL:" "")
case "$url" in
http://*|https://*) ;;
*) url="https://$url" ;;
esac
open_url "$url"
;;
2025-07-21 12:57:44 +03:30
Incognito\ URL)
url=$(get_input "Enter incognito URL:" "")
case "$url" in
http://*|https://*) ;;
*) url="https://$url" ;;
esac
if ! $SWALLOW brave-bin --incognito "$url" >/dev/null 2>&1; then
$NOTIFIER "Error" "Failed to open incognito window" 2>/dev/null || \
echo "Error: Failed to open incognito window" >&2
exit 1
fi
;;
2025-07-11 11:19:32 +03:30
YouTube)
query=$(get_input "Search YouTube:" "")
open_url "https://youtube.com/results?search_query=$query"
;;
2025-07-21 12:57:44 +03:30
Safebooru)
query=$(get_input "Search Safebooru:" "")
open_url "https://safebooru.org/index.php?page=post&s=list&tags=$query"
;;
coasteen.github.io)
open_url "https://coasteen.github.io/www/"
;;
2025-07-11 11:19:32 +03:30
*)
$NOTIFIER "Error" "Invalid selection: $CHOICE" 2>/dev/null || \
echo "Error: Invalid selection: $CHOICE" >&2
exit 1
;;
esac