X-Git-Url: https://git.draconx.ca/gitweb/fvwmconf.git/blobdiff_plain/01c0c7e8df66f488f498bf088a5850def432f41c..6ea5fd2e47b06873f28160fc414f4ef90c82f2fe:/scripts/bgmenu.sh diff --git a/scripts/bgmenu.sh b/scripts/bgmenu.sh new file mode 100755 index 0000000..98a2a1d --- /dev/null +++ b/scripts/bgmenu.sh @@ -0,0 +1,47 @@ +#!/bin/sh +# +# Copyright © 2008, 2017 Nick Bowler +# +# Generates an FVWM menu for selecting the PNG images found in a given +# directory. Thumbnails for the images are generated on the fly using +# the thumbnailer.zsh script. Menu items run the specified function +# with the filename as the first argument. + +thumber="$FVWM_USERDIR/scripts/thumbnail.zsh --size x160" +xaspect=$FVWM_USERDIR/scripts/C/xaspect +menu=MenuWallpaper +func=SetWallpaper + +lastarg= +dashdash= +for arg; do + if test ${lastarg:+y}; then + arg=$lastarg=$arg + lastarg= + fi + + case $dashdash$arg in + --menu=*) menu=${arg#--menu=} ;; + --func=*) func=${arg#--func=} ;; + --menu|--func) lastarg=$arg ;; + --) dashdash=: ;; + -*) printf '%s: unrecognized argument: %s\n' "$0" "$arg" 1>&2; exit 1 ;; + *) set x "$@" "$arg"; shift + esac + + shift +done + +case $# in +1) dir=$1 ;; +*) printf 'usage: %s [options] directory\n' "$0" 1>&2 +esac + +size=`$xaspect -dimensions` +find $1 -maxdepth 1 -name "*$size.png" -print0 -exec $thumber {} \; | + awk -F '\0' '{ + gsub(/["\\]/, "\\\\&"); + caption = gensub(/.*\/(.*)\..*/, "\\1", 1, $1); + print "AddToMenu", menuname, "\"" caption "*" $2 "*\"", + funcname, "\"" $1 "\"" + }' "menuname=$menu" "funcname=$func"