#!/bin/bash # * Defaults heading=" " protocol="capture-html" template="w" # * Functions function debug { if [[ -n $debug ]] then function debug { echo "DEBUG: $@" >&2 } debug "$@" else function debug { true } fi } function die { echo "$@" >&2 exit 1 } function usage { cat </{s|.*([^<]+).*|\1|i;p;q};' <<<"$html") || heading="A web page with no name" debug "Using heading: $heading" elif [[ -n $readability ]] then debug "Using readability" else usage echo die "I need somethin' ta go on, Cap'n!" fi # ** Check URL # The URL shouldn't be empty [[ -n $url ]] || url="http://example.com" # ** URL-encode html heading=$(urlencode <<<"$heading") || die "Unable to urlencode heading." url=$(urlencode <<<"$url") || die "Unable to urlencode URL." html=$(urlencode <<<"$html") || die "Unable to urlencode HTML." # ** Send to Emacs emacsclient "org-protocol://$protocol?template=$template&url=$url&title=$heading&body=$html"