1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
#!/bin/sh
# elvis: pin -- Search Pinboard bookmarks (https://pinboard.in)
# author: jason ryan • http://jasonwryan.com
. surfraw || exit 1
w3_config_hook () {
def SURFRAW_pinboard_tags "$SURFRAW_tags"
def SURFRAW_pinboard_user "$SURFRAW_user"
def SURFRAW_pinboard_new 0
def SURFRAW_pinboard_popular 0
}
w3_usage_hook () {
cat <<EOF
Usage: $w3_argv0 [options] [search words]...
Description:
Surfraw search Pinboard bookmarks (http://pinboard.in)
Local options:
Default search (without any options) includes tags, titles and descriptions
and is not limited to a specific number of search terms.
-popular | -p Search popular tags
-recent | -r Search recent tags
-tags=TAGS | -t=TAGS Only search tags (separate a maximum of 3 TAGS with
a "+" eg., unix+linux)
-user=NAME | -u=NAME Search a user's bookmarks
EOF
w3_global_usage
}
w3_parse_option_hook () {
opt="$1"
optarg="$2"
case "$opt" in
-p* ) setoptyn SURFRAW_pinboard_popular 1 ;;
-r* ) setoptyn SURFRAW_pinboard_new 1 ;;
-t=*) setopt SURFRAW_pinboard_tags $optarg ;;
-u=*) setopt SURFRAW_pinboard_user $optarg ;;
*) return 1 ;;
esac
return 0
}
# create tag string
tags () {
local IFS=+
for tag in $SURFRAW_pinboard_tags; do
printf "%s" "t:$tag/"
done
}
w3_config
w3_parse_args "$@"
# w3_args now contains a list of arguments
escaped_args=$(w3_url_of_arg $w3_args)
base_url="https://pinboard.in/"
# check for recent & popular
if [ "$SURFRAW_pinboard_new" = 1 ]; then
suffix="recent/"
elif [ "$SURFRAW_pinboard_popular" = 1 ]; then
suffix="popular"
fi
# Run through the other possibilities...
if [ -z "$w3_args" ]; then
if [ -n "$SURFRAW_pinboard_user" ] && [ -n "$SURFRAW_pinboard_tags" ]; then
w3_browse_url "${base_url}u:$SURFRAW_pinboard_user/$(tags)"
elif [ -n "$SURFRAW_pinboard_tags" ]; then
w3_browse_url "${base_url}$(tags)"
elif [ -n "$SURFRAW_pinboard_user" ]; then
w3_browse_url "${base_url}u:$SURFRAW_pinboard_user"
else w3_browse_url "$base_url${suffix}"
fi
elif [ -n "$w3_args" ]; then
w3_browse_url "${base_url}search/?query=${escaped_args}&all=Search+All"
else
w3_browse_url "${base_url}"
fi
|