diff options
Diffstat (limited to '.graveyard/noise/noise')
-rwxr-xr-x | .graveyard/noise/noise | 186 |
1 files changed, 186 insertions, 0 deletions
diff --git a/.graveyard/noise/noise b/.graveyard/noise/noise new file mode 100755 index 00000000..615277a6 --- /dev/null +++ b/.graveyard/noise/noise @@ -0,0 +1,186 @@ +#! /bin/sh + +noise_set() { # set a variable + case "$1" in + (-q|--quiet) echo=: ; shift ;; + (*) echo=echo ;; + esac + case $# in + (0) ## print all noise variables + env | sed -n ' + s/^noise_\([[:alnum:]_]\+\)=\(.*\)$/[35;4m\1[;35m = [32m\2[m/p + ' | sort + ;; + (1) ## print value the specified variable + eval "echo \"[35;4m$1[0;35m = [0;32m\$noise_$1[m\"" + ;; + (*) ## set the specified variable + if echo "$1" | grep -q '[^[:alnum:]_]' ; then + fail invalid variable name "[4m$1" + return 23 + fi + eval "old=\"\$noise_$1\"" + if test "x$old" = "x$2" ; then + eval "$echo \"[35;4m$1[0;35m is already [0;32m$2[m\"" + elif test -z "$old" ; then + eval "export noise_$1='$2' ; $echo \ +\"[35;4m$1[0;35m set to [0;32m$2[m\"" + else + eval "export noise_$1='$2' ; $echo \ +\"[35;4m$1[0;35m changed from $old to [0;32m$2[m\"" + fi + ## write variable to $env + if grep -q "^$1=" "$env" ; then + cache="`cat $env`" + echo "$cache" | + sed "s'^\($1\)=\(.*\)\$'\1=\'$2\''" > $env + else + echo "$1='$2'" >>$env + fi + ;; + esac +} + +noise_unset() { # unset a variable + case "$1" in + (-q|--quiet) echo=: ; shift ;; + (*) echo=echo ;; + esac + case $# in + (1) ## + unset "noise_$1" + cache="`cat $env`" + echo "$cache" | + sed -n "/^$1=/!p" > $env + ;; + (*) + fail "broken commandline: $@" + ;; + esac +} + +noise_quit() { # exit + echo "[35mGood bye![m" + exit +} + +fail() { + echo "[31mFAIL: $*[m" + return 23 +} + +cleanup() { + kill $jobs + rm -f $linefeed $env + rmdir /tmp/noise/$$ 2>/dev/null + rmdir /tmp/noise 2>/dev/null +} + +exec 2>&1 +qname="`readlink -f "$0"`" +dirname="`dirname "$qname"`" +export HOME='/home/noise' +if test -d "$dirname/modules" ; then + export NOISE_PATH="${NOISE_PATH+$NOISE_PATH:}$dirname/modules" + export NOISE_PATH="${NOISE_PATH+$NOISE_PATH:}$HOME/noise/modules" +fi +mkdir -p /tmp/noise/$$ +linefeed="/tmp/noise/$$/linefeed" +env="/tmp/noise/$$/environment" +trap cleanup EXIT +mkfifo $linefeed +touch $env +## +## +## +readline() { + { read REPLY && echo "$REPLY" ; } | sed -n " + s/[']//g + s/~%/\n/g + s/\([^\\]\)\([#<>]\)/\1\\\\\2/g + s:^/\([a-z_]\+\)\([[:space:]]\+\(.*\)\)\?$:command=\1; args='\3';:p;t + s@^\([[:alnum:]_/+-]\+\):[[:space:]]*\(.*\)@command=lang; args='\1 \2';@p;t + s@^\![[:space:]]*\(.*\)@command=play; args='\1';@p;t + s:.*:command='$noise_default_command'; args='&';:p;t + " +} +## +## +## +while echo -n "$noise_prompt" && eval "`readline`" ; do + ## modcall + for dir in `echo "$NOISE_PATH" | tr : \ ` ; do + module="$dir/$command" + if test -x "$module" ; then +#echo foo $module:$@: + #shift + eval 'NOISE="$0" NOISE_pid="$$" NOISE_linefeed="$linefeed" "$module"' "$args" + continue 2 + fi + done + ## funcall + if type noise_$command | grep -q function ; then + eval 'noise_$command' "$args" + continue + fi + ## + fail unknown command "[4m$command[m" +done <$linefeed & +jobs="${jobs+$jobs }`jobs -p`" +## +## +## +cat<<EOF +[35mWelcome to [1;4m23.shack[;35m version 0.9 beta 4 \ +commit ` + cd $dirname && + git log -n 1 | head -n 1 | cut -d\ -f 2 | dd count=23 bs=1 2>/dev/null +`... +[;33m +## Motto Of The Day\ +[m +[33;1mJoin the 23.shack-dev-team, we've got ` + sloccount $dirname/* | + sed -n ' + s/.*(SLOC)[[:space:]]*=[[:space:]]*\([0-9]\+\)$/\1/p + '` SLOC, ` + { + ls $dirname/modules/ + test -d ~noise/modules && ls ~noise/modules/ + } | sort | uniq | wc -l + ` mods, +`grep ^- $dirname/TODO | wc -l`+ TODOs and drive the irregular Hackathon @shackspace. +Follow [34;4mhttp://twitter.com/shackspam[;1;33m [5mFTW[;1;33m! +[;33m +## Hints\ +[m +Start your telnet session with [4mrlwrap[;m for MAXIMUM profit. +Get online-help with [32m/help[m. +[m +EOF +# TODO: MOTD-candidates: +#twitter: #shackspam +#mail: shockspasm@googlemail.com +#irc: freenode/#shackspace +#afk: @shackspace +## +## +## +exec >>$linefeed +## +## +## +echo '/set -q default_command espeak' +echo '/set -q prompt "[30mREADY.[m~%"' +## +## +## +while read REPLY; do + case $REPLY in + (/quit) echo /quit ; exit ;; + (*) tr \; \\n | grep . ;; + esac<<EOF +$REPLY +EOF +done +#### end of file. |