summaryrefslogtreecommitdiffstats
path: root/util/bin/magic
diff options
context:
space:
mode:
authortv <tv@iiso>2011-09-24 22:13:06 +0200
committertv <tv@iiso>2011-09-24 22:13:06 +0200
commit6d052057793681d073b33d07ce007c8fcfb3b542 (patch)
tree3314041446bde3b5ba1f01e6522e3c03c289ad1d /util/bin/magic
parente692ab13d032df6e8c96bf1ec840f366122dca1f (diff)
//util magic: initial extract
Diffstat (limited to 'util/bin/magic')
-rwxr-xr-xutil/bin/magic41
1 files changed, 41 insertions, 0 deletions
diff --git a/util/bin/magic b/util/bin/magic
new file mode 100755
index 00000000..04a7017d
--- /dev/null
+++ b/util/bin/magic
@@ -0,0 +1,41 @@
+#! /bin/sh
+#
+# magic $name $command $file < $content
+#
+
+name="$1"; shift
+command="$1"; shift
+file="$1"; shift
+
+bs="# begin krebs magic${name+ <$name>}"
+es="# end krebs magic${name+ <$name>}"
+
+case $1 in
+ (print)
+ echo "$bs"
+ cat
+ echo "$es"
+ ;;
+ (create)
+ $0 has || $0 print >> $file < /dev/null
+ $0 replace
+ ;;
+ (destroy)
+ if $0 has; then
+ cache"`cat $file`"
+ echo "$cache" | sed "/^$bs$/,/^$es$/d" > $file
+ fi
+ ;;
+ (has)
+ grep -q "^$bs\$" $file && grep -q "^$es\$" $file
+ ;;
+ (replace)
+ $0 destroy && $0 create
+ ;;
+ (clear)
+ $0 replace < /dev/null
+ ;;
+ (*)
+ echo 'Error 1: You are made of stupid!' >&2
+ exit 23
+esac