]> git.draconx.ca Git - fvwmconf.git/commitdiff
Update thumbnail.zsh to use zsh conventions.
authorNick Bowler <nbowler@ellipticsemi.com>
Wed, 28 May 2008 19:23:37 +0000 (15:23 -0400)
committerNick Bowler <nbowler@ellipticsemi.com>
Wed, 28 May 2008 19:23:37 +0000 (15:23 -0400)
scripts/thumbnail.zsh

index 245cba2d2069bf1b342d0d4f7c9ba190ec46ad65..a96780392c65b2e83e45a269056570ce692cfe81 100755 (executable)
@@ -3,7 +3,7 @@
 music=/stuff/music
 thumbs="$HOME/.fvwm/.thumbs"
 
-if [ ! -d "$thumbs" ]; then
+if ! [[ -d "$thumbs" ]]; then
        mkdir "$thumbs" || exit 1
 fi
 
@@ -11,15 +11,15 @@ size="x128"
 printimg=""
 ismusic=""
 
-while [ "${1#--}" != "$1" -a "$1" != "-" ]; do
-       if [ "$1" = "--small" ]; then
+while [[ "${1#--}" != "$1" && "$1" != "-" ]]; do
+       if   [[ "$1" == "--small" ]]; then
                size="56"
-       elif [ "$1" = "--size" ]; then
+       elif [[ "$1" == "--size"  ]]; then
                size="$2"
                shift
-       elif [ "$1" = "--music" ]; then
+       elif [[ "$1" = "--music"  ]]; then
                ismusic="yes"
-       elif [ "$1" = "--image" ]; then
+       elif [[ "$1" = "--image"  ]]; then
                printimg="yes"
        else
                echo "unrecognised option: $1" 1>&2
@@ -29,32 +29,32 @@ while [ "${1#--}" != "$1" -a "$1" != "-" ]; do
 done
 [ "$1" = "-" ] && shift
 
-if ! expr match "$size" '^\([0-9]*\(x[0-9]\+\)\?\)$' >/dev/null 2>&1; then
+if ! [[ "$size" =~ '^([0-9]*(x[0-9]+)?)$' ]]; then
        echo "invalid size specification: $size" 1>&2
        exit 1
 fi
 
-if [ -z "$1" ]; then
+if [[ -z "$1" ]]; then
        echo "usage: thumbnail.zsh [--small|--size <spec>] [--image] [--music] path" 1>&2
        exit 1
 fi
 
-if [ -n "$ismusic" ]; then
-       imgpath="$music/`dirname "${1#$music}"`/cover.jpg"
-       [ ! -f "$imgpath" ] && imgpath="${imgpath%jpg}png"
+if [[ -n "$ismusic" ]]; then
+       imgpath="$music/$(dirname "${1#$music}")/cover.jpg"
+       [[ ! -f "$imgpath" ]] && imgpath="${imgpath%jpg}png"
 else
        imgpath="$1"
 fi
 
-[ ! -f "$imgpath" ] && exit 0
+[[ ! -f "$imgpath" ]] && exit 0
 
 image="$(readlink -f -- "$imgpath")"
-[ ! -f "$image" ] && exit 0
+[[ ! -f "$image" ]] && exit 0
 
-thumb="$thumbs/`echo -n $image | md5sum - | cut -d ' ' -f 1`_$size.png"
-if [ -f "$thumb" ]; then
-       mtime_s="`stat -c %Y -- "$image"`"
-       mtime_t="`stat -c %Y -- "$thumb"`"
+thumb="$thumbs/$(echo -n $image | md5sum - | cut -d ' ' -f 1)_$size.png"
+if [[ -f "$thumb" ]]; then
+       mtime_s="$(stat -c %Y -- "$image")"
+       mtime_t="$(stat -c %Y -- "$thumb")"
        if [ "$mtime_s" -gt "$mtime_t" ]; then
                convert -scale "$size" "$image" "$thumb"
        fi