{ feh
, glib
, findutils
, gnugrep
, coreutils
, writeScriptBin
, backgrounds_directory ? "$HOME/Immagini/Sfondi"
}:
let
  find = "${findutils}/bin/find";
  grep = "${gnugrep}/bin/grep";
  shuf = "${coreutils}/bin/shuf";
in
writeScriptBin "update-background" ''
  #!/bin/sh
  if [ $# -eq 0 ]; then
    image=`${find} ${backgrounds_directory} -type f | ${grep} -v "/\." | ${shuf} -n 1`
  else
    image="$1"
  fi
  echo "image: $image"
  ${feh}/bin/feh --bg-fill --no-fehbg "$image"
  ${glib}/bin/gsettings set org.gnome.desktop.background picture-uri "file://$image"
  true
''
