]> git.draconx.ca Git - fvwmconf.git/blob - scripts/bgmenu.sh
Use mpdexec for key bindings.
[fvwmconf.git] / scripts / bgmenu.sh
1 #!/bin/sh
2 #
3 # Copyright © 2008, 2017 Nick Bowler
4 #
5 # Generates an FVWM menu for selecting the PNG images found in a given
6 # directory.  Thumbnails for the images are generated on the fly using
7 # the thumbnailer.zsh script.  Menu items run the specified function
8 # with the filename as the first argument.
9
10 thumber="$FVWM_USERDIR/scripts/thumbnail.zsh --size x160"
11 xaspect=$FVWM_USERDIR/scripts/C/xaspect
12 menu=MenuWallpaper
13 func=SetWallpaper
14
15 lastarg=
16 dashdash=
17 for arg; do
18   if test ${lastarg:+y}; then
19     arg=$lastarg=$arg
20     lastarg=
21   fi
22
23   case $dashdash$arg in
24   --menu=*) menu=${arg#--menu=} ;;
25   --func=*) func=${arg#--func=} ;;
26   --menu|--func) lastarg=$arg ;;
27   --) dashdash=: ;;
28   -*) printf '%s: unrecognized argument: %s\n' "$0" "$arg" 1>&2; exit 1 ;;
29   *) set x "$@" "$arg"; shift
30   esac
31
32   shift
33 done
34
35 case $# in
36 1) dir=$1 ;;
37 *) printf 'usage: %s [options] directory\n' "$0" 1>&2
38 esac
39
40 size=`$xaspect -dimensions`
41 find $1 -maxdepth 1 -name "*$size.png" -print0 -exec $thumber {} \; |
42   awk -F '\0' '{
43     gsub(/["\\]/, "\\\\&");
44     caption = gensub(/.*\/(.*)\..*/, "\\1", 1, $1);
45     print "AddToMenu", menuname, "\"" caption "*" $2 "*\"",
46           funcname, "\"" $1 "\""
47   }' "menuname=$menu" "funcname=$func"