wp

a wallpaper switcher
Log | Files | Refs | README | LICENSE

commit 1fc54fe23d7bac93bac438d03b883bb03e74e6dc
Author: Matthias Balk <mbalk@mbalk.de>
Date:   Mon,  3 Jan 2022 18:41:35 +0100

first version of wp with plugins 'default' (required) and 'pexels'

Diffstat:
ALICENSE | 19+++++++++++++++++++
AREADME | 38++++++++++++++++++++++++++++++++++++++
Aplugins/default | 6++++++
Aplugins/pexels | 36++++++++++++++++++++++++++++++++++++
Awp | 20++++++++++++++++++++
5 files changed, 119 insertions(+), 0 deletions(-)

diff --git a/LICENSE b/LICENSE @@ -0,0 +1,19 @@ +Copyright © 2022 Matthias Balk + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the “Software”), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README b/README @@ -0,0 +1,38 @@ +wp -- a wallpaper switcher +========================== + +`wp` uses `feh` to display a wallpaper on your desktop. + + +PLUGINS +------- + +`wp` itself does nothing without a plugin which provides an image. + +A plugin is an executable which echoes an image's path to stdout. + +The `default` plugin just grabs a random file from `$HOME/.wp/*jpg`. + +The `pexels` plugin downloads an image from pexels.com and saves it to a +temporary file. Don't forget to edit the configuration in the plugin to fit +your needs! + +Requirements are mentioned in a comment in each plugin's source code. + +Note that `feh` can also show remote files if it is linked against `libcurl`. + +You are welcome to bring your own plugins! + + +EXAMPLES +-------- + +$ wp default # use wp's `default` plugin +$ wp # shorthand for the `default` plugin +$ wp pexels # use wp's `pexels` plugin + +You may want to write this to your `.xinitrc`: +wp default & + +Or in your crontab: +30 * * * * DISPLAY=:0 wp default diff --git a/plugins/default b/plugins/default @@ -0,0 +1,6 @@ +#!/bin/sh + +# wp -- a wallpaper switcher +# Copyright 2022 Matthias Balk + +echo "`ls -1 $HOME/.wp/*jpg | sort -R | head -1`" diff --git a/plugins/pexels b/plugins/pexels @@ -0,0 +1,36 @@ +#!/bin/bash + +# wp -- a wallpaper switcher +# Copyright 2022 Matthias Balk + +# requires `bash` (for $RANDOM), `bc`, `curl` and `jq` + +# configuration +SEARCH_TERM='Norwegen' +LOCALE='de-DE' +API_SECRET='YOUR PEXELS.COM API SECRET GOES HERE!' +PICS_COUNT=80 # number of pics to choose from; max 80, default 15 +# end configuration + +data="`mktemp`" +curl -s -H "Authorization: $API_SECRET" \ + "https://api.pexels.com/v1/search?query=$SEARCH_TERM&locale=$LOCALE&per_page=$PICS_COUNT&page=1" \ + > $data + +results=`jq -r ".total_results" $data` +if [ "$results" = "0" -o "$results" = "null" -o "$results" = "" ]; then + exit 1 +fi + +if [ $results -lt $PICS_COUNT ]; then + mod=$results +else + mod=$PICS_COUNT +fi +RANDOM=$$ +pic=`echo "$RANDOM % $mod" | bc` +url=`jq -r ".photos[$pic].src.original" $data` + +target="`mktemp`" +curl -s "$url" > "$target" +echo $target diff --git a/wp b/wp @@ -0,0 +1,20 @@ +#!/bin/sh + +# wp -- a wallpaper switcher +# Copyright 2022 Matthias Balk + +# requires `feh` + +set -e + +if [ $# -lt 1 ]; then + plugin="default" +else + plugin="$@" +fi + +plugin_dir="$(dirname `readlink -f $0`)/plugins" +img="$("$plugin_dir/$plugin")" +if [ -n "$img" ]; then + feh --no-fehbg --bg-fill "$img" +fi