#!/bin/rc # theme - set a rio(1) theme # usage: theme [-d] [-p /path/to/themedir] [-l] [-r] name # requires: # - patched rio with theme support (https://ftrv.se/14) # - .theme files in $themedir # set some defaults rfork en themedir=$home/lib/rio fn default{ >/dev/theme cat <<'...' rioback 777777 back ffffff high cccccc border 999999 text 000000 htext 000000 title 55aaaa ltitle 9eeeee hold 000099 lhold 005dbb palehold 4993dd paletext 666666 size ff0000 menubar 448844 menuback eaffea menuhigh 448844 menubord 88cc88 menutext 000000 menuhtext eaffea ... 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:' $themedir 'is not a directory' exit nodir case nofile echo 'error: theme file for "'$arg'" not found in' $themedir exit nofile case nolist echo 'error: no valid themes found in' $themedir exit nolist case nopath echo 'error: no path specified' usage case notheme echo 'error: no theme file specified' usage case unknown echo 'error: unknown option "'$flag'"' usage } } fn help{ echo 'options:' echo ' -d for default colors' echo ' -p for setting $themedir (default='$themedir')' echo ' -l for list of available themes' echo ' -r for random theme' echo 'requires:' echo ' - rio patched for theme support (see https://ftrv.se/14)' echo ' - .theme files in $themedir' echo ' e.g.,' $themedir/my_awesome.theme usage } fn list{ if(! test -d $themedir) error nodir themelist=`{walk -f $themedir | grep -e '*.theme' | sort} switch($themelist){ case '' error nolist case * echo 'available themes in' $themedir':' for(i in $themelist) echo ' -' `{basename $i .theme} exit } } fn random{ if(! test -d $themedir) error nodir randtheme=`{fortune <{walk -f $themedir | grep -e '*.theme'}} switch($randtheme){ case '' error nolist case * cat $randtheme >/dev/theme exit } } fn usage{ echo 'usage: theme [-d] [-p /path/to/themedir] [-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 * themedir=$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(~ $#theme 1) arg=$theme if not error notheme case 1 arg=$1 case * usage } if(! test -d $themedir) error nodir if(! test -f $themedir/$arg.theme) error nofile cat $themedir/$arg.theme >/dev/theme