fdd76fc5 |
1 | #!/bin/bash |
2 | PIDFILE=${PIDFILE:-/tmp/wallpaper.pid} |
3 | |
4 | trap "rm -f $PIDFILE" SIGUSR1 |
5 | |
6 | # set background function (requires input) |
7 | function 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 | |
22 | if [[ -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 |
27 | fi |
28 | |
29 | # create PIDFILE |
30 | echo $$ > $PIDFILE |
31 | |
32 | ## MAIN ## |
33 | # do we have input? |
34 | if [[ ! -z $1 ]]; then |
35 | WPAPERS=$1 |
36 | else |
37 | # No input. We'll use our predefined directory |
38 | WPAPERS="/home/danix/Pictures/wallpapers/black" |
39 | fi |
40 | |
41 | wpapers $WPAPERS |
42 | |