dotfiles/.local/bin/bookmarks
2025-02-17 06:08:25 +00:00

28 lines
706 B
Bash
Executable File

#!/bin/bash -e
shopt -s extglob
if [ "$1" = -p ]; then
BROWSER="$BROWSER --private-window"
elif [[ "$(xdotool getwindowfocus getwindowname)" != *'Mozilla Firefox' ]]; then
BROWSER="$BROWSER --new-window"
fi
mapfile -t list < <(grep -Pv '^(#|$)' "$XDG_CONFIG_HOME/bookmarks")
q="$(printf '%s\n' '' "${list[@]}" | dmenu -l 16)"
if [ -z "$q" ]; then
exec $BROWSER
elif [[ "$q" == *://* ]]; then
url="${q/*+( )/}"
if [ "$1" = -p ] || [[ "$url" == http?(s)://* ]]; then
exec $BROWSER "$url"
fi
exec xdg-open "$url"
fi
if [[ "$q" == *.* ]] && [[ "$q" != *' '* ]]; then
exec $BROWSER "$q"
fi
exec $BROWSER "https://searx.gmoker.com/search?q=$(jq -Rr '@uri' <<< "$q")"