#!/bin/sh . slib help() { cat << EOF ${0}: Wrapper script to set wallpapers options: -d [File] Select a wallpaper or a directory -c Remove the current wallpaper -h Print this message and exit NOTE: default directory is ~/.config/wallpapers EOF exit 0 } check_program "xwallpaper" if [ "${#}" = 0 ]; then #FIXME: use XDG_CONFIG input="${HOME}/.config/wallpapers" elif [ "${#}" != 1 ] && [ "${#}" != 2 ]; then invalid_use fi while getopts "hcd:" option; do case "${option}" in c) run "xwallpaper --clear" ;; d) input="${OPTARG}" ;; h) help ;; *) invalid_use -h ;; esac done shift $((OPTIND - 1)) [ "${#}" != 0 ] && invalid_use if [ -n "${input}" ]; then case $(file -L -b --mime-type "${input}") in image/*) image="${input}" ;; inode/directory) waldir="${input}" ;; *) err "Couldn't read given file" ;; esac fi if [ -n "${waldir}" ]; then image=$(find "${waldir}" -iregex '.*.\(jpg\|jpeg\|png\|gif\)' 2>/dev/null \ | shuf -n 1 ) fi [ -z "${image}" ] && err "No image file found" run "xwallpaper --zoom ${image}" "${image}"