]> git.draconx.ca Git - fvwmconf.git/commitdiff
thumbnailer: Follow only one level of symbolic link.
authorNick Bowler <nbowler@draconx.ca>
Fri, 20 Oct 2017 01:39:17 +0000 (21:39 -0400)
committerNick Bowler <nbowler@draconx.ca>
Fri, 20 Oct 2017 01:39:17 +0000 (21:39 -0400)
Since my music is all in git annex now, the thumbnailer follows the
cover art symlinks all the way to the annex object directory.  This is
less than helpful, since the intention was to locate the album scan
directory.  Change the --image mode to just read the link once and
then stop.

scripts/thumbnail.zsh

index de5e44f30516a69dffe2b711f2723909e2f8c8d1..a27574931951d46f1c2dcce66cbdfee4ecd23fad 100755 (executable)
@@ -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
 # 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"