diff options
author | Suleyman Farajli <suleyman@farajli.net> | 2024-07-24 18:41:48 +0400 |
---|---|---|
committer | Suleyman Farajli <suleyman@farajli.net> | 2024-07-24 18:41:48 +0400 |
commit | 587b3d126a16def5a58df53359be8bf97dd58b01 (patch) | |
tree | 3d3b49ae9f56cd012ec144909c2e0b5fd018b7a3 | |
parent | bfc1e11c950fbc9758cd8841c3c2fa143091f2c2 (diff) |
wallpaper script rewritten
-rwxr-xr-x | scripts/setwp | 56 |
1 files changed, 47 insertions, 9 deletions
diff --git a/scripts/setwp b/scripts/setwp index d80c10e..86bfb9b 100755 --- a/scripts/setwp +++ b/scripts/setwp @@ -1,18 +1,56 @@ #!/bin/sh -# Wrapper script for setting wallpaper +err() { + echo "${0}": "${1}" + exit 1 +} -program_name=setwp -for argument in $@; -do - [ ! -e $argument ] && { echo $program_name: cannot access "'$argument'": No such file or directory && exit 2; } +help() { +cat << EOF +$0: Wrapper script to set wallpapers - [ -d $argument ] && wallpaper_list="$wallpaper_list $(ls -d $argument/*)" +options: + -d [File] Select a wallpaper or a directory + -h Print this message and exit + -c Remove the current wallpaper - [ -f $argument ] && wallpaper_list="$wallpaper_list $argument" - +NOTE: default wallpaper directory is ~/.config/wallpapers +EOF +} + +waldir="${XDG_CONFIG_HOME:-$HOME}/.config/wallpapers" + +while getopts "hcd:" option; do + case "${option}" in + h) + help + exit 0 + ;; + c) + xwallpaper --clear > /dev/null 2>&1 \ + err "Couldn't clear wallpaper" + exit 0 + ;; + d) buf="${OPTARG}" ;; + *) err 'add -h for help' ;; + esac done -xwallpaper --zoom $(shuf -en 1 $wallpaper_list) +if [ -n "${buf}" ]; then + case $(file -b --mime-type "${buf}") in + image/*) image="${buf}" ;; + inode/directory) waldir="${buf}" ;; + *) err "Couldn't read given file" ;; + esac +fi + +if [ -z "${image}" ]; then + image=$(find "${waldir}" -iregex '.*\.jpeg\|.*\.jpng\|.*\.png' 2>/dev/null \ + | shuf -n 1 2>/dev/null) +fi + +xwallpaper --zoom "${image}" > /dev/null 2>&1 || err "Couldn't set wallpaper" + +echo "${image}" |