#!/bin/rc # wall - set a rio(1) wallpaper # usage: wall [-d] [-p /path/to/imgdir] [-l] [-r] name # requires: # - patched rio with theme support (https://ftrv.se/14) # - compatible .img files in $imgdir; see image(6) # set some defaults rfork en imgdir=$home/lib/rio/wall fn default{ >/dev/theme echo rioback 777777 exit } fn error{ switch($1){ case nodev echo 'error: /dev/theme not found' echo 'is rio running and is it patched?' exit nodev case nodir echo 'error:' $imgdir 'is not a directory' exit nodir case nofile echo 'error: "'$arg'.img" not found in' $imgdir exit nofile case nolist echo 'error: no valid image files found in' $imgdir exit nolist case nopath echo 'error: no path specified' usage case noimg echo 'error: no image file specified' usage case unknown echo 'error: unknown option "'$flag'"' usage } } fn help{ echo 'options:' echo ' -d for default background' echo ' -p for setting $imgdir (default='$imgdir')' echo ' -l for list of available images' echo ' -r for random image' echo 'requires:' echo ' - rio patched for theme support (see https://ftrv.se/14)' echo ' - compatible .img files in $imgdir; see image(6)' echo ' e.g.,' $imgdir/my_awesome.img usage } fn list{ if(! test -d $imgdir) error nodir imglist=`{walk -f $imgdir | grep -e '*.img' | sort} switch($imglist){ case '' error nolist case * echo 'available images in' $imgdir':' for(i in $imglist) echo ' -' `{basename $i .img} exit } } fn random{ if(! test -d $imgdir) error nodir randimg=`{fortune <{walk -f $imgdir | grep -e '*.img'}} switch($randimg){ case '' error nolist case * cat $randimg >/dev/theme exit } } fn usage{ echo 'usage: wall [-d] [-p /path/to/imgdir] [-l] [-r] name' exit usage } # main body if(! test -f /dev/theme) error nodev while(~ $1 -*){ switch($1){ case -p switch($2){ case '' -* error nopath case * imgdir=$2 shift 2 } case -d default case -h -help --help help case -l list case -r random case * flag=$1 error unknown } } switch($#*){ case 0 if(~ $#wallpaper 1) arg=$wallpaper if not error noimg case 1 arg=$1 case * usage } if(! test -d $imgdir) error nodir if(! test -f $imgdir/$arg.img) error nofile echo rioback $imgdir/$arg.img >/dev/theme