Skip to content

Instantly share code, notes, and snippets.

@io41
Created January 20, 2012 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save io41/1648537 to your computer and use it in GitHub Desktop.
Save io41/1648537 to your computer and use it in GitHub Desktop.
#!/bin/sh
# Save this in a file in an empty dir, then run.
__global=./
__object=__mytype
__object_id=my-id
# All events go here
exec 10>$__global/post_config_events
# Make a test script
cat > myscript <<EOF
#!/bin/sh
echo "Hi, from my script. About to emit an event, foo"
echo "$__object/$__object_id foo" >&10
echo "Event 'foo' emitted. k, thx, bye"
EOF
# Make a test event handler
mkdir -p __mytype/my-id
cat > __mytype/my-id/post_config <<EOF
#!/bin/sh
echo "Handling event $1"
EOF
chmod +x myscript
chmod +x __mytype/my-id/post_config
# Run the thing that emits the event
$(pwd)/myscript
# Run post config event handlers
sh <<EOF
$(sort -u post_config_events | sed "s#\([^ ]*\) \(.*\)#$__global\1/post_config \2#")
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment