From 3a046a65669db0b81e185113fb85ce401937a287 Mon Sep 17 00:00:00 2001 From: zachir Date: Mon, 27 Feb 2023 00:19:31 -0600 Subject: fix bm to work without flags --- bm | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 100 insertions(+), 7 deletions(-) (limited to 'bm') diff --git a/bm b/bm index 98d3f0f..c963fac 100755 --- a/bm +++ b/bm @@ -16,26 +16,119 @@ printhelp () { } #}}} +#{{{ BROWSERSBYCMD +# Native binaries +type basilisk >/dev/null 2>&1 && CANBSC="bsc" +type firedragon >/dev/null 2>&1 && CANFDC="fdc" +type firefox >/dev/null 2>&1 && CANFFC="ffc" +type librewolf >/dev/null 2>&1 && CANLWC="lwc" +type qutebrowser >/dev/null 2>&1 && CANQBC="qbc" +type brave >/dev/null 2>&1 && CANBRA="brave" +[ -n "$WAYLAND_DISPLAY" ] && \ + type wl-copy >/dev/null 2>&1 && CANCLIPB="clip" +[ -z "$WAYLAND_DISPLAY" -a -n "$DISPLAY" ] && \ + type xclip >/dev/null 2>&1 && CANCLIPB="clip" +# Flatpaks +LIST="$(flatpak list)" +echo "$LIST" | grep -q "org.mozilla.firefox" && CANFFC="ffc" +echo "$LIST" | grep -q "com.brave.Browser" && CANBRA="brave" +echo "$LIST" | grep -q "io.gitlab.librewolf-community" && \ + CANLWC="lwc" +echo "$LIST" | grep -q "org.qutebrowser.qutebrowser" && \ + CANQBC="qbc" +#}}} + #{{{ getopts unset ARG -while getopts "hbrflqxwd:u:" o; do case "${o}" in +while getopts "hbBcrflqxwd:u:" o; do case "${o}" in b) BSC="y" ;; + B) BRA="y" ;; r) FDC="y" ;; f) FFC="y" ;; l) LWC="y" ;; q) QBC="y" ;; + c) CLIPB="y" ;; x) ARG="$ARG-x " ;; w) ARG="$ARG-w " ;; d) ARG="$ARG-d $OPTARG ";; - u) ARG="$ARG-u $OPTARG " ;; + u) URL="$OPTARG " ;; *) printhelp ;; esac done #}}} +#{{{ clip +clip () { + ARG="$@" + if [ -n "$WAYLAND_DISPLAY" -a -n "$CANCLIPB" ]; then + echo -n $URL | wl-copy ${ARG%u} + elif [ -n "$DISPLAY" -a -n "$CANCLIPB" ]; then + echo -n $URL | xclip ${ARG%-u} + fi +} +#}}} + +#{{{ bra +bra () { + if [ -n "$CANBRA" ]; then + if type brave >/dev/null 2>&2; then + brave $@ + else + flatpak run com.brave.Browser $@ + fi + fi +} +#}}} + +#{{{ Check display server if -w or -x not provided +if [ -z "$DMENU" ]; then + if [ -n "$WAYLAND_DISPLAY" ]; then + DMENU="bemenu" + elif [ -n "$DISPLAY" ]; then + DMENU="dmene" + else + print "Can't tell if Wayland or X; what gives?\n" + exit 1 + fi +fi +#}}} + #{{{ main -[ -n "$BSC" ] && bsc $ARG -[ -n "$FDC" ] && fdc $ARG -[ -n "$FFC" ] && ffc $ARG -[ -n "$LWC" ] && lwc $ARG -[ -n "$QBC" ] && qbc $ARG +if [ -n "$BSC$FDC$FFC$LWC$QBC" ]; then + ARG="$ARG -u $URL" +fi +echo $ARG +[ -n "$BSC" ] && exec bsc $ARG +[ -n "$FDC" ] && exec fdc $ARG +[ -n "$FFC" ] && exec ffc $ARG +[ -n "$LWC" ] && exec lwc $ARG +[ -n "$QBC" ] && exec qbc $ARG +[ -n "$BRA" ] && exec bra $ARG +[ -n "$CLIPB" ] && exec clip $ARG +if [ -z "$CLIPB$BSC$FDC$FFC$LWC$QBC" ]; then + BROWSERSINSTALLED="" + for i in CLIPB BSC FDC FFC LWC QBC BRA; do + if [ -n "$(eval "echo \$CAN${i}")" ]; then + [ -n "$BROWSERSINSTALLED" ] && STARTLINE="\n" || STARTLINE="" ; + [ -z "$URL" -a "$i" = "CLIPB" ] && continue + BROWSERSINSTALLED="${BROWSERSINSTALLED}${STARTLINE}$(eval "echo \$CAN${i}")" + fi + done + echo "$BROWSERSINSTALLED" + [ -z "$BROWSERSINSTALLED" ] && \ + printf "No suitable browsers!\n" && exit 1 + BROWSERSEL="$(echo "$BROWSERSINSTALLED" | $DMENU -p "Browsers" -l 10 $ARG)" + [ -z "$BROWSERSEL" ] && \ + printf "No browser selected!\n" && exit 1 + case "$BROWSERSEL" in + clip) + $BROWSERSEL $ARG + ;; + brave) + bra $URL + ;; + *) + $BROWSERSEL $ARG -u $URL + ;; + esac +fi #}}} -- cgit v1.2.3