#!/bin/bash # launch Uzbl once per each URI in stdin . "$(ffoom path)" || exit 3 ffoo import pretty SATURNIN_XURIS_NOTIFICATIONS=true SATURNIN_XURIS_LIMIT=100 SATURNIN_XURIS_ALWAYS_RUN=false SATURNIN_XURIS_UNIQ=true SATURNIN_XURIS_CHOICE="${SATURNIN_XURIS_CHOICE:-false}" FFOO_DEBUG=true usage() { mkusage "[-u|--uniq] [-a|--always-run] [-l|--limit N] [-c|--choose] [-C|--choice-cmd COMMAND]" } get_i3_wsname() { # # Get current workspace name # i3-msg -t get_workspaces \ | jq '.[] | {focused, name}' \ | grep -F -A 1 'focused": true' \ | grep name \ | cut -d\" -f4 } enum_bins() { echo uzbl-browser echo vimb echo firefox echo opera-rh echo opera-beta echo opera echo wget } decide_bin() { # # Decide what browser to use # local context="$(hostname -s)/$(get_i3_wsname)" debug -v context case "$context" in hugo/*) echo vimb ;; fullmoon/*) echo uzbl-browser ;; *) echo uzbl-browser ;; esac } maybe_uniq() { $SATURNIN_XURIS_UNIQ || { cat; return; } sort | uniq } notify() { $SATURNIN_XURIS_NOTIFICATIONS || return 0 local summary="saturnin-xuris" local body="$1" notify-send -a saturnin-xuris "$summary" "$body" } open_from() { local list="$1" local count=$(wc -l <"$list") test "$count" -gt $SATURNIN_XURIS_LIMIT && { notify "too much URIs; giving up: $count > $SATURNIN_XURIS_LIMIT" return 1 } test "$count" -eq 0 && { $SATURNIN_XURIS_ALWAYS_RUN && $SATURNIN_XURIS_BIN & return 0 } while read uri; do $SATURNIN_XURIS_BIN "$uri" & done < "$list" } while true; do case $1 in -a|--always-run) SATURNIN_XURIS_ALWAYS_RUN=true; shift ;; -b|--bin) SATURNIN_XURIS_BIN="$2"; shift; shift ;; -c|--choose) SATURNIN_XURIS_CHOICE="enum_bins | saturnin dmenu"; shift ;; -C|--choice-cmd) SATURNIN_XURIS_CHOICE="$2"; shift; shift ;; -l|--limit) SATURNIN_XURIS_LIMIT=$2; shift; shift ;; -u|--uniq) SATURNIN_XURIS_UNIQ=true; shift ;; -U|--no-uniq) SATURNIN_XURIS_UNIQ=false; shift ;; -*) usage ;; "") break ;; *) usage ;; esac done debug -v SATURNIN_XURIS_ALWAYS_RUN \ SATURNIN_XURIS_CHOICE \ SATURNIN_XURIS_LIMIT \ SATURNIN_XURIS_UNIQ SATURNIN_XURIS_URI_LIST=$(mktemp -t saturnin-xuris.XXXXXXXX) cat | maybe_uniq | grep . >"$SATURNIN_XURIS_URI_LIST" # choice of URI has been made; we may try to use dmenu bash -n <<<"$SATURNIN_XURIS_CHOICE" SATURNIN_XURIS_BIN=$(eval "$SATURNIN_XURIS_CHOICE") SATURNIN_XURIS_BIN="${SATURNIN_XURIS_BIN:-$(decide_bin)}" debug -v SATURNIN_XURIS_BIN open_from "$SATURNIN_XURIS_URI_LIST" rm "$SATURNIN_XURIS_URI_LIST"