ref: f3afdf563f784c0a5703496f48c1a72dff4617f4
dir: /themes/
#!/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)
# - <name>.theme files in $themedir
############################
## defaults / definitions ##
############################
rfork en
themedir=$home/lib/theme
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=$home/lib/theme)'
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 ' - <name>.theme files in $themedir'
echo ' * ex:' $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: themes [-h help] [-d default] [-p /path/to/themedir] [-l list] [-r random] <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