tenebrous /random_wallpaper

#!/bin/sh

# simple script for random wallpaper
# ----------------------------------
# vermaden [AT] interia [DOT] pl
# http://toya.net.pl/~vermaden/links.htm

if [ ! -d ${1} ]; then
  echo "usage: $( basename ${0} ) DIRECTORY"
  exit 1
fi

if [ ! -x $( which feh ) ]; then
  echo "feh ( http://linuxbrit.co.uk/feh ) not avialable"
  exit 1
fi

WALLS_LIST=$( ls -1R ${1} | egrep "^.*\.([jJ][pP][eEgG][gG]*|[gG][iI][fF]|[pP][nN][gG])+$" )

for WALL in ${WALLS_LIST} ;do
  WALLS_COUNT=$(( ${WALLS_COUNT} + 1 ));
done

RANDOM=$( ( time ps aux ; date +"%S" ; w ) 2>&1 | cksum | awk '{print substr($0, 0, 5)}' )
WINNER=$(( ${RANDOM} % ${WALLS_COUNT} + 1 ))
feh --bg-scale ${1}/$( echo "${WALLS_LIST}" | sed -n ${WINNER}p )