I have this script in my bin directory as ~/bin/mktw
so that I can quickly and conveniently create or update Tiddlers via the Node.js server listening on port 8080.
#!/bin/bash
TW5URL="http://127.0.0.1:8080"
PROG=${0##*/}
if [ -z "$1" ] ; then
2>&1 echo "Syntax: cat /tmp/inputfile | $PROG <Tiddler> [tag1] [tag2] [tag3] ..."
exit 1
else
TIDDLER="$1"
shift
fi
function urlencode() {
echo -n "$*" | python -c 'import urllib,sys; print urllib.quote(sys.stdin.read())'
}
function to_json() {
echo -n "$*" | python -c 'import json,sys; print json.dumps(sys.stdin.read())'
}
TAGS=""
while (( "$#" )) ; do
if [ -n "$TAGS" ] ; then
TAGS="${TAGS}, "
fi
TAGS="${TAGS}$(to_json $1)"
shift
done
An example of how I use it with (one) of my TiddlyWiki's, is to keep a daily copy of my bash history:
#!/bin/bash
YESTERDAY="$(date --date=yesterday +%Y%m%d)"
HISTFILE=~/.bash_history
HISTSIZE=1000
HISTFILESIZE=30000
HISTCONTROL="ignoreboth"
HISTTIMEFORMAT="%Y%m%d %T "
set -o history
(echo '```bash' ; \
history \
| grep -P "^\s*[0-9]+\s+${YESTERDAY}\s+" \
| perl -pe 's/^\s*[0-9]+\s+[0-9]+\s+//' ; \
echo '```') | ~/bin/mktw "${YESTERDAY}: Bash History" "Bash History"