Exit properly on errors in icom.
[utils.git] / planime
diff --git a/planime b/planime
index dfb8d64..3dab1dd 100755 (executable)
--- a/planime
+++ b/planime
@@ -15,6 +15,7 @@ scorefile() {
 }
 
 findfile() {
+    if [ -n "$debug" ]; then echo "finding base='$1', ep='$2', qual='$3'" >&2; fi
     local file tail eq eqt m matches max score
     matches=()
     for file in "$1"*; do
@@ -45,27 +46,33 @@ findfile() {
     max=
     for m in "${matches[@]}"; do
        score="$(scorefile "$m")"
+       if [ -n "$debug" ]; then echo "found \`$m': score $score" >&2; fi
        if [ -z "$max" ] || [ "$score" -gt "$max" ]; then
            max="$score"
            file="$m"
        fi
     done
+    if [ -n "$debug" ]; then echo "using \`$file'" >&2; fi
     echo "$file"
     return 0
 }
 
 origargs=("$0" "$@")
 cmdline=(mplayer -fs -ass)
-unset pretend
+debug=
+unset pretend printfile
 
 while [ "${1:0:1}" = - ]; do
     a="$1"
     shift
     case "$a" in
        -h)
-           echo "usage: planime [-htC] [-s PAR VAL] [NAME-QUAL] [EP|.] [TYPE-QUAL]" >&2
+           echo "usage: planime [-fdhtC] [-A PLAYER-ARGS... ;] [-s PAR VAL] [--] [NAME-QUAL] [EP|.] [TYPE-QUAL]" >&2
            exit 0
            ;;
+       -d)
+           debug=y
+           ;;
        -t)
            cmdline=("${cmdline[@]}" -ao oss:/dev/dsp1)
            ;;
@@ -88,6 +95,16 @@ while [ "${1:0:1}" = - ]; do
            saveval="$1"
            shift
            ;;
+       -f)
+           printfile=y
+           ;;
+       --)
+           break
+           ;;
+       *)
+           echo "planime: unknown option \`$a'"
+           exit 1
+           ;;
     esac
 done
 
@@ -216,6 +233,8 @@ if [ "`hostname`" = pc6 -o "`hostname`" = pc7 -a "$DISPLAY" = :1 ]; then chwp=y;
 
 if [ -n "$pretend" ]; then
     echo "${cmdline[@]}" "$file"
+elif [ -n "$printfile" ]; then
+    echo "$file"
 else
     if [ "$chwp" = y ]; then (sleep 2; randomwp) & fi
     "${cmdline[@]}" "$file"