summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorroot <root@shack.(none)>2010-05-04 23:59:14 +0200
committerroot <root@shack.(none)>2010-05-04 23:59:14 +0200
commit59907ceaa2211a3c1600e8febd4752dd18fe896f (patch)
treef9b5e22403896b3c2913d544efb668343d2a8c32
parent667de73a8186f23df8357391cd96c3eee96eab54 (diff)
noise: accept double-quotes and extended /set
New /set syntax: /set [-q|--quiet] [NAME [VALUES]]
-rwxr-xr-xnoise69
1 files changed, 42 insertions, 27 deletions
diff --git a/noise b/noise
index 36c86185..9fc7e6e2 100755
--- a/noise
+++ b/noise
@@ -1,28 +1,36 @@
#! /bin/sh
noise_set() { # set a variable
- if test "x$1" = x ; then
- env | sed -rn '
- s/^noise_([[:alnum:]_]+)=(.*)$/\1 = \2/p
- ' | sort
- elif test "x$2" = x ; then
- eval "echo \"$1 = \$noise_$1\""
- else
- if echo "$1" | grep -q '[^[:alnum:]_]' ; then
- fail invalid variable name "$1"
- return 23
- fi
- eval "old=\"\$noise_$1\""
- if test "x$old" = "x$2" ; then
- eval "echo \"$1 is already $2\""
- elif test -z "$old" ; then
- eval "export noise_$1='$2' ; echo \
+ case "$1" in
+ (-q|--quiet) echo=: ; shift ;;
+ (*) echo=echo ;;
+ esac
+ case $# in
+ (0) ## print all noise variables
+ env | sed -rn '
+ s/^noise_([[:alnum:]_]+)=(.*)$/\1 = \2/p
+ ' | sort
+ ;;
+ (1) ## print value the specified variable
+ eval "echo \"$1 = \$noise_$1\""
+ ;;
+ (*) ## set the specified variable
+ if echo "$1" | grep -q '[^[:alnum:]_]' ; then
+ fail invalid variable name "$1"
+ return 23
+ fi
+ eval "old=\"\$noise_$1\""
+ if test "x$old" = "x$2" ; then
+ eval "$echo \"$1 is already $2\""
+ elif test -z "$old" ; then
+ eval "export noise_$1='$2' ; $echo \
\"$1 set to $2\""
- else
- eval "export noise_$1='$2' ; echo \
+ else
+ eval "export noise_$1='$2' ; $echo \
\"$1 changed from $old to $2\""
- fi
- fi
+ fi
+ ;;
+ esac
}
noise_quit() { # exit
@@ -54,28 +62,36 @@ mkfifo $linefeed
##
##
readline() {
- { read && echo $REPLY ; } | sed -rn "
- s/['\"]//g
+ { read && echo "$REPLY" ; } | sed -rn "
+ s/[']//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 "READY." && eval "`readline`" ; do
- #echo "command: $command; args: $args"
+##
+##
+##
+export noise_prompt="READY.
+"
+export noise_default_command=espeak
+##
+##
+##
+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
shift
- NOISE="$0" NOISE_linefeed="$linefeed" "$module" $args
+ eval 'NOISE="$0" NOISE_linefeed="$linefeed" "$module"' "$args"
continue 2
fi
done
## funcall
if type noise_$command &>/dev/null ; then
- noise_$command $args
+ eval 'noise_$command' "$args"
continue
fi
##
@@ -94,7 +110,6 @@ EOF
##
##
exec >>$linefeed
-echo /set default_command espeak
while read ; do
case $REPLY in
(/quit) echo /quit ; exit ;;