#!/bin/sh -u # # Add a link page URL to a list of link pages. # - Cameron Simpson 04aug2000 # cmd=$0 : ${LINKPAGEPATH:=$HOME/.linkpages} verbose=1 ##[ -t 0 ] && verbose=1 usage="Usage: $cmd [-d dir] [topic[,topic...] [urls...]" badopts= if [ $# -gt 0 ] && [ "x$1" = x-d ] then LINKPAGEPATH=$2; shift; shift export LINKPAGEPATH fi topic= if [ $# -gt 0 ] then case $1 in ''|*://*) topic=$LINKPAGETOPIC ;; # URL - take default topic *) topic=$1; shift ;; esac fi [ -n "$topic" ] || topic=`lastvalue addlinkpage` if [ -z "$topic" ] then echo "$cmd: missing topic and no \$LINKPAGETOPIC envvar" >&2 badopts=1 fi if [ $# = 0 ] then [ -n "$DISPLAY" ] && { set -- `xclip -o` || exit 1; } [ $# = 0 ] && { echo "$cmd: no args and nothing from xclip" >&2 badopts=1 } fi case "$topic" in */*) echo "$cmd: bad topic \"$topic\"" >&2 badopts=1 ;; esac topicfiles= for basetopic in `echo "$topic" | tr , ' '` do topicfile= for dir in `unpath "$LINKPAGEPATH"` do for subdir in urls/ '' do topicfile=$dir/$subdir$basetopic [ -f "$topicfile" ] && break done [ -f "$topicfile" ] && break done [ -f "$topicfile" ] || { echo "$cmd: can't find topic \"$basetopic\" in \$LINKPAGEPATH" >&2 badopts=1 continue } topicfiles="$topicfiles $topicfile" done [ $badopts ] && { echo "$usage" >&2; exit 2; } lastvalue addlinkpage "$topic" xit=0 for url do [ "x$url" = x- ] && { url=`cat` || exit 1; } for topicfile in $topicfiles do [ $verbose ] && echo "$url >> $topicfile" >&2 printf "%s\n" "$url" >>"$topicfile" done done exit $xit