#!/bin/bash # plasma (forked from noiseAndDirt ) # give me some plasma and noise and dirt for wallpaper # required: imagemagick, nitrogen, xrandr # usage: plasma --help # benchmark start START=$(date +%s.%N) # checks command -v convert >/dev/null 2>&1 || { echo "I need imagemagick convert, exiting." >&2; exit 1; } command -v nitrogen >/dev/null 2>&1 || { echo "I need nitrogen, exiting." >&2; exit 1; } command -v xrandr >/dev/null 2>&1 || { echo "I need xrandr, exiting." >&2; exit 1; } # store & vars tmp="/tmp/noiseAndDirt-$RANDOM-$$" trap '[ -n "$tmp" ] && rm -fr "$tmp"' EXIT # comment out this line to keep all images mkdir -m 700 "$tmp" || { echo '!! unable to create a tmpdir' >&2; tmp=; exit 1; } # these are temporary noise="$tmp/noise.png" # noise dirt="$tmp/dirt.png" # dirt dirt2="$tmp/dirt2.png" # dirt2 dirt3="$tmp/dirt3.png" # dirt3 tmpcomp="$tmp/tmp.png" # tmpcomp tmpcomp2="$tmp/tmp2.png" # tmpcomp2 tmpcomp3="$tmp/tmp3.png" # tmpcomp3 final="$tmp/final.png" # final # keep backups and where keepsome="1" # bool keep="$HOME/data/noiseAndDirt" # boolean, if true single image is generated monitorsforce="0" # for me debug="0" # resolution mx=1920; my=1200 (( monitorsforce )) && mx=3840 # if single-tile then we need bigger res # if backup/keepsome is enabled, then we want pngcrush if (( keepsome )); then command -v pngcrush >/dev/null 2>&1 || { echo "I need pngcrush, exiting." >&2; exit 1; } mkdir -p "$keep" || exit fi # print progress dot () { printf "." } touch "$noise" "$dirt" "$dirt2" "$tmpcomp" "$final" || exit # help if [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then cat < /dev/null then (echo "$1 running, restarting" killall -w "$1" "${1}" &) & else echo "$1 wasn't running" fi } setwall () { nitrogen --set-tiled "$final" } keepfunc () { backup="$keep/noiseAndPlasma-${RANDOM}.png" cp "$final" "$backup" #mogrify -depth 8 "$backup" # convert to 8 bit per channel cd "$keep" || exit pngcrush -q -ow "$backup" printf "b%s" "$c" #echo "stored as $backup" #cp "$tmp/plasma.png" "$keep/plasma-${RANDOM}.png" } # How many monitors connected if (( monitorsforce )); then monitors="1" else monitors=$(xrandr -d :0 -q | grep ' connected' -c) fi # is monitors a number if ! [[ $monitors =~ ^[1-9]+$ ]]; then >&2 echo "No monitors detected, assuming one." monitors="1" fi for (( c=1; c<=monitors; c++ )) do (( debug )) && echo "monitor $c" printf " %s " "$c" noise (( debug )) && echo dirt & dirt2 & dirt3 & plasmagen; wait (( debug )) && echo compose rotateMaybe #degrade if (( monitorsforce )); then # tile just one nitrogen --set-tiled "$final" > /dev/null 2>&1 || exit else # each monitor has its own bitmap nitrogen --head=$(( c - 1 )) --set-tiled "$final" > /dev/null 2>&1 || exit fi (( keepsome )) && keepfunc & (( debug )) && beepspeakers done restart wbar > /dev/null 2>&1 wait # benchmark end printf " " END=$(date +%s.%N) DIFF=$(echo "$END - $START" | bc -l) printf "noiseAndDirt done in %.0f seconds\n" "$DIFF" # report disk usage if backup/keepsome is enabled (( keepsome )) && printf " backup disk space used: " && du -hs "$keep"