summaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authortv <tv@iiso>2011-09-24 22:37:03 +0200
committertv <tv@iiso>2011-09-24 22:37:03 +0200
commitf87e292ecb4d2be09b17d4c68d7c40031e924489 (patch)
tree7f3b970921c5b0493f6b77ed20bda82caab2b6c1 /util
parent88212635961bac86a8c9c1b0626f8a016bcc9b70 (diff)
//util magic: fix major typos
Diffstat (limited to 'util')
-rwxr-xr-xutil/bin/magic56
1 files changed, 33 insertions, 23 deletions
diff --git a/util/bin/magic b/util/bin/magic
index 218c8d43..8f3c7e04 100755
--- a/util/bin/magic
+++ b/util/bin/magic
@@ -1,36 +1,46 @@
#! /bin/sh
#
-# magic name command file < content
+# magic NAME create FILE < CONTENT
+# magic NAME update FILE < CONTENT
+# magic NAME destroy FILE
#
bs="# begin krebs magic <$1>"
es="# end krebs magic <$1>"
-case $1 in
- (print)
+has() {
+ grep -q "^$bs$" $3 && grep -q "^$es$" $3
+}
+
+create() {
+ destroy "$@"
+ cache="`cat $3`"
+ {
+ echo "$cache"
echo "$bs"
cat
echo "$es"
- ;;
- (create)
- $0 $1 has $3 || $0 $1 print $3 >> $3 < /dev/null
- $0 $1 replace $3
- ;;
- (destroy)
- if $0 $1 has $3; then
- cache"`cat $3`"
- echo "$cache" | sed "/^$bs$/,/^$es$/d" > $3
- fi
- ;;
- (has)
- grep -q "^$bs\$" $3 && grep -q "^$es\$" $3
- ;;
- (replace)
- $0 $1 destroy $3 && $0 $1 create $3
- ;;
- (clear)
- $0 $1 replace $3 < /dev/null
- ;;
+ } >$3
+}
+
+#retrieve() {
+#}
+
+update() {
+ ! has "$@" || create "$@"
+}
+
+destroy() {
+ if has "$@"; then
+ cache="`cat $3`"
+ echo "$cache" | sed "/^$bs$/,/^$es$/d" >$3
+ fi
+}
+
+case $2 in
+ (create) create "$@" ;;
+ (update) update "$@" ;;
+ (destroy) destroy "$@" ;;
(*)
echo 'Error 1: You are made of stupid!' >&2
exit 23