diff options
Diffstat (limited to 'scripts/gui/swall')
| -rwxr-xr-x | scripts/gui/swall | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/scripts/gui/swall b/scripts/gui/swall new file mode 100755 index 0000000..8e5ffb6 --- /dev/null +++ b/scripts/gui/swall @@ -0,0 +1,68 @@ +#!/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) + #FIXME: use `run` function + killall picom + xwallpaper --clear + picom & + exit 0 + ;; + + 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}" |
