From 676c6a27158a4c7a3132b9f2e3b5ad1d5d71da23 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Fri, 21 Dec 2012 17:33:23 -0300 Subject: [PATCH] dsv/dsv: record source URL in dsv-* file; new option -u to show it This adds a second line to the dsv-* files, containing the source URL. dsv -u shows the URL. Compatibility with older versions of dsv: - "dsv -u" will fail with an error if running on an old data sheet database, while the rest of dsv works as before - to update the database, run the usual "dsv setup ..." (most dsv-using projects have a "make dsv" target for this) - older version of dsv will not be able to display data sheets or paths if run with an updated database --- dsv/dsv | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/dsv/dsv b/dsv/dsv index 1496ffd..d623cbe 100755 --- a/dsv/dsv +++ b/dsv/dsv @@ -30,12 +30,13 @@ DSV_DIR=.dsv usage() { - echo "usage: $0 [-p] " 2>&1 + echo "usage: $0 [-p|-u] " 2>&1 echo " $0 help" 2>&1 echo " $0 [ls]" 2>&1 echo " $0 setup ..." 2>&1 echo 2>&1 echo " -p show the path instead of displaying the file " 2>&1 + echo " -u show source URL instead of displaying the file " 2>&1 exit 1 } @@ -78,7 +79,7 @@ flush() fi eval for n in $name $alias\; do \ 'nm=`echo "$n" | sed "s/%/%25/g;s|/|%2F|g"`;' \ - echo '"$ds"' '>$DSV_DIR/dsv-$nm'\; \ + \{ echo '"$ds"'\; echo '"$url"'\; \} '>$DSV_DIR/dsv-$nm'\; \ done name= alias= @@ -157,7 +158,18 @@ search() if [ -d $DSV_DIR ]; then name=`echo "$1" | sed 's/%/%25/g;s|/|%2F|g'` if [ -r "$DSV_DIR/dsv-$name" ]; then - file=`cat "$DSV_DIR/dsv-$name"` + if $show_url; then + url=`sed 1d "$DSV_DIR/dsv-$name"` + if [ "$url" ]; then + echo "$url" + exit + else + echo "$DSV_DIR/dsv-$name" \ + "does not contain an URL - please regenerate" 1>&2 + exit 1 + fi + fi + file=`sed 1q "$DSV_DIR/dsv-$name"` if [ ! -r "$DSV_DIR/$file" ]; then echo "$1 -> $file: does not exist" 2>&1 exit 1 @@ -179,10 +191,15 @@ search() path=false +show_url=false if [ "$1" = -p ]; then path=true shift fi +if [ "$1" = -u ]; then + show_url=true + shift +fi case "$1" in help|-*) usage;;