mass update.
[my-dotfiles.git] / oldies / wallpaper.sh
CommitLineData
fdd76fc5 1#!/bin/bash
2PIDFILE=${PIDFILE:-/tmp/wallpaper.pid}
3
4trap "rm -f $PIDFILE" SIGUSR1
5
6# set background function (requires input)
7function wpapers () {
8 if [[ -f $1 ]]; then
9 # We have a single file as input
10 feh --bg-fill --no-fehbg $1
11 exit 0
12 elif [[ -d $1 ]]; then
13 # directory as input
14 while true; do
15 BGIMG=$(find $1 -type f -print | shuf -n1)
16 feh --bg-fill --no-fehbg $BGIMG
17 sleep 5m
18 done
19 fi
20}
21
22if [[ -f $PIDFILE ]]; then
23 # PIDFILE exists, so I guess there's already an instance running
24 # let's kill it and run again
25 kill $(cat $PIDFILE) > /dev/null 2>&1
26 rm $PIDFILE
27fi
28
29# create PIDFILE
30echo $$ > $PIDFILE
31
32## MAIN ##
33# do we have input?
34if [[ ! -z $1 ]]; then
35 WPAPERS=$1
36else
37 # No input. We'll use our predefined directory
38 WPAPERS="/home/danix/Pictures/wallpapers/black"
39fi
40
41wpapers $WPAPERS
42