X-Git-Url: https://git.draconx.ca/gitweb/fvwmconf.git/blobdiff_plain/cb413f94ce2cd07780082b28613856651082a925..01c0c7e8df66f488f498bf088a5850def432f41c:/scripts/thumbnail.zsh diff --git a/scripts/thumbnail.zsh b/scripts/thumbnail.zsh index de5e44f..a275749 100755 --- a/scripts/thumbnail.zsh +++ b/scripts/thumbnail.zsh @@ -1,6 +1,6 @@ #!/usr/bin/env zsh # -# Copyright © 2008 Nick Bowler +# Copyright © 2008, 2017 Nick Bowler # # Simple thumbnail generator for use with FVWM. Thumbnails can be generated at # any desired size, and are cached for future use. Prints the cached filename @@ -10,6 +10,22 @@ # This is free software: you are free to do what the fuck you want to. # There is NO WARRANTY, to the extent permitted by law. +# resolve_file [file] +# +# If the argument is a symbolic link, print the target of that link. +# Otherwise, prints the basename of file. +resolve_file () { + test $# -eq 1 || return + + # Ensure filename won't be confused for any kind of find argument... + case $1 in + /*) :;; + *) set x "./$1"; shift + esac + + find "$1" -prune \( -type l -printf '%l' -o -printf '%f' \) +} + if [[ -z "$MUSIC" ]]; then MUSIC=/home/music fi @@ -60,8 +76,11 @@ else fi [[ ! -f "$imgpath" ]] && exit 0 - -image="$(readlink -f -- "$imgpath")" +image=`resolve_file "$imgpath"` +case $image in +/*) :;; +*) image=`dirname $imgpath`/$image +esac [[ ! -f "$image" ]] && exit 0 thumb="$thumbs/$(echo -n $image | md5sum - | cut -d ' ' -f 1)_$size.png"