Loading .shell/bin/wallpaper +49 −16 Original line number Diff line number Diff line #!/usr/bin/env python # A wrapper around nitrogen that repeats a set command at randomly picked # intervals #!/bin/sh # At a random interval between MIN_DELAY_MINS (default: 45 minutes) and # MAX_DELAY_MINS (default: 120 minutes) minutes choose an image from # IMAGE_DIRECTORY and set it as the desktop wallpaper. # # If python is available execs the python version wallpaper.py to avoid forking # several additional processes per iteration other than the setter. import os import sys import time import random import subprocess set -eu : ${MIN_DELAY_MINS:=45} ${MAX_DELAY_MINS:=120} : ${IMAGES_DIRECTORY:=${HOME}/.backgrounds} MIN_DELAY_MINS = 45 MAX_DELAY_MINS = 120 . ~/.shell/funcs if [ $# -gt 0 ]; then echo >&2 "Using '$*' as setter command" elif has feh; then set feh --no-fehbg --no-xinerama --bg-fill else echo >&2 "No setter command found" exit 2 fi while 1: subprocess.call([ 'nitrogen', '--set-zoom-fill', '--random', '{HOME}/.backgrounds'.format(**os.environ), ]) time.sleep(random.randint(MIN_DELAY_MINS * 60, MAX_DELAY_MINS * 60)) if has python; then export MIN_DELAY_MINS export MAX_DELAY_MINS export IMAGES_DIRECTORY exec python ~/.shell/bin/wallpaper.py "$@" fi if has find; then list() { find "${IMAGES_DIRECTORY}" -type f; } else list() { ls -r1 --quoting-style=literal "${IMAGES_DIRECTORY}"; } fi if has shuf; then choose() { shuf -n1; } elif has sort && has head; then choose() { sort -R | head -n1; } else echo >&2 "No selection command found" exit 2 fi min_delay=$((MIN_DELAY_MINS * 60)) max_delay=$((MAX_DELAY_MINS * 60)) dif_delay=$((max_delay - min_delay)) while true; do "$@" "`list|choose`" sleep `seq $min_delay $max_delay | choose` done .shell/bin/wallpaper.py 0 → 100644 +33 −0 Original line number Diff line number Diff line #!/usr/bin/env python # At a random interval between MIN_DELAY_MINS (default: 45 minutes) and # MAX_DELAY_MINS (default: 120 minutes) minutes choose an image from # IMAGE_DIRECTORY and set it as the desktop wallpaper. import os import sys import time import random import subprocess from os import path MIN_DELAY_SECS = int(os.environ.get('MIN_DELAY_MINS', 45)) * 60 MAX_DELAY_SECS = int(os.environ.get('MAX_DELAY_MINS', 120)) * 60 IMAGES_DIRECTORY = path.expanduser( os.environ.get('IMAGES_DIRECTORY', '~/.backgrounds')) def all_files(): for dirpath, _, filenames in os.walk(IMAGES_DIRECTORY): for filename in filenames: yield path.join(dirpath, filename) if len(sys.argv) > 0: cmd = sys.argv[1:] + [None] else: cmd = ['feh', '--no-fehbg', '--no-xinerama', '--bg-fill', None] while 1: cmd[-1] = random.choice(list(all_files())) subprocess.call(cmd) time.sleep(random.randint(MIN_DELAY_SECS, MAX_DELAY_SECS)) Loading
.shell/bin/wallpaper +49 −16 Original line number Diff line number Diff line #!/usr/bin/env python # A wrapper around nitrogen that repeats a set command at randomly picked # intervals #!/bin/sh # At a random interval between MIN_DELAY_MINS (default: 45 minutes) and # MAX_DELAY_MINS (default: 120 minutes) minutes choose an image from # IMAGE_DIRECTORY and set it as the desktop wallpaper. # # If python is available execs the python version wallpaper.py to avoid forking # several additional processes per iteration other than the setter. import os import sys import time import random import subprocess set -eu : ${MIN_DELAY_MINS:=45} ${MAX_DELAY_MINS:=120} : ${IMAGES_DIRECTORY:=${HOME}/.backgrounds} MIN_DELAY_MINS = 45 MAX_DELAY_MINS = 120 . ~/.shell/funcs if [ $# -gt 0 ]; then echo >&2 "Using '$*' as setter command" elif has feh; then set feh --no-fehbg --no-xinerama --bg-fill else echo >&2 "No setter command found" exit 2 fi while 1: subprocess.call([ 'nitrogen', '--set-zoom-fill', '--random', '{HOME}/.backgrounds'.format(**os.environ), ]) time.sleep(random.randint(MIN_DELAY_MINS * 60, MAX_DELAY_MINS * 60)) if has python; then export MIN_DELAY_MINS export MAX_DELAY_MINS export IMAGES_DIRECTORY exec python ~/.shell/bin/wallpaper.py "$@" fi if has find; then list() { find "${IMAGES_DIRECTORY}" -type f; } else list() { ls -r1 --quoting-style=literal "${IMAGES_DIRECTORY}"; } fi if has shuf; then choose() { shuf -n1; } elif has sort && has head; then choose() { sort -R | head -n1; } else echo >&2 "No selection command found" exit 2 fi min_delay=$((MIN_DELAY_MINS * 60)) max_delay=$((MAX_DELAY_MINS * 60)) dif_delay=$((max_delay - min_delay)) while true; do "$@" "`list|choose`" sleep `seq $min_delay $max_delay | choose` done
.shell/bin/wallpaper.py 0 → 100644 +33 −0 Original line number Diff line number Diff line #!/usr/bin/env python # At a random interval between MIN_DELAY_MINS (default: 45 minutes) and # MAX_DELAY_MINS (default: 120 minutes) minutes choose an image from # IMAGE_DIRECTORY and set it as the desktop wallpaper. import os import sys import time import random import subprocess from os import path MIN_DELAY_SECS = int(os.environ.get('MIN_DELAY_MINS', 45)) * 60 MAX_DELAY_SECS = int(os.environ.get('MAX_DELAY_MINS', 120)) * 60 IMAGES_DIRECTORY = path.expanduser( os.environ.get('IMAGES_DIRECTORY', '~/.backgrounds')) def all_files(): for dirpath, _, filenames in os.walk(IMAGES_DIRECTORY): for filename in filenames: yield path.join(dirpath, filename) if len(sys.argv) > 0: cmd = sys.argv[1:] + [None] else: cmd = ['feh', '--no-fehbg', '--no-xinerama', '--bg-fill', None] while 1: cmd[-1] = random.choice(list(all_files())) subprocess.call(cmd) time.sleep(random.randint(MIN_DELAY_SECS, MAX_DELAY_SECS))