diff --git a/dsv/dsv b/dsv/dsv index d623cbe..d40ff66 100755 --- a/dsv/dsv +++ b/dsv/dsv @@ -30,7 +30,7 @@ DSV_DIR=.dsv usage() { - echo "usage: $0 [-p|-u] " 2>&1 + echo "usage: $0 [-p] [-u] " 2>&1 echo " $0 help" 2>&1 echo " $0 [ls]" 2>&1 echo " $0 setup ..." 2>&1 @@ -158,17 +158,6 @@ search() if [ -d $DSV_DIR ]; then name=`echo "$1" | sed 's/%/%25/g;s|/|%2F|g'` if [ -r "$DSV_DIR/dsv-$name" ]; then - 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 @@ -176,9 +165,19 @@ search() fi if $path; then echo "`pwd`/$DSV_DIR/$file" - else + elif ! $show_url; then ${DSV_VIEWER:-${DSV_PDFVIEWER:-xdg-open}} "$DSV_DIR/$file" fi + if $show_url; then + url=`sed 1d "$DSV_DIR/dsv-$name"` + if [ "$url" ]; then + echo "$url" + else + echo "$DSV_DIR/dsv-$name" \ + "does not contain an URL - please regenerate" 1>&2 + exit 1 + fi + fi exit fi fi @@ -192,14 +191,17 @@ search() path=false show_url=false -if [ "$1" = -p ]; then - path=true - shift -fi -if [ "$1" = -u ]; then - show_url=true - shift -fi + +while true; do + case "$1" in + -p) path=true + shift;; + -u) show_url=true + shift;; + -*) usage;; + *) break;; + esac +done case "$1" in help|-*) usage;;