March 31st, 2004 | Published in Uncategorized
I accidentally opened up the BBEdit “Default Worksheet” stationery today and discovered what a BBEdit worksheet actually is: It’s a text buffer that processes shell commands.
So if you’ve got a command in the worksheet file like:
you just press CMD-return and it kicks back the output as if it had been typed in the shell. The sample stationery page offers a bunch of examples, like:
find /usr/include -name “*.h” | grep exception | xargs bbedit
which feeds all the header files in /usr/include that contain the string “exception” into BBEdit for editing.
It was pretty simple to set up a worksheet to utilize mtsend.py as a blogging tool from within BBEdit. CMD-returning on a given line causes the output of the line to appear in the document. Passed through a little sed, the output is munged into another command. The document itself forms a sort of “blog editing pipeline checklist” to play around with.
Python’s whitespace/indenting requirements make it a real PitA for quick hacking if you’re not a Python person anyhow. I have to run some of mtsend’s output through a lot of sed munging because my attempts at hacking out the bits I didn’t need ended up throwing syntax errors over unexepected indentation. My choice: Learn more python or just go to the CPU expense of passing the output through a familiar tool.
cutare my friends, Python is a chilly acquaintance.
(and this is a much bigger nuisance) BBEdit, even though it’s running a bash shell within the Worksheet document, doesn’t inherit the user’s bash environment, meaning that my attempts to stay neat and clean by putting mtsend.py in my own ~/bin were thwarted by BBEdit not understanding that ~/bin is in my $PATH. There’s supposed to be a fix for this from Apple but it involves turning my .bashrc into a plist. Apple’s document on the matter says “It is actually fairly simple process to set environment variables for processes launched by a specific user,” which begs the question of why it doesn’t just do that anyhow. If I’m smart enough to modify my .bashrc, I’d like to be trusted with e-z access to my labor without having to reconcile it with a plist.
I put my current blogging worksheet within the extended entry if you’re dying of curiosity. Note the ugly need to declare where MTSEND is until such time as I can make OS X just honor my .bashrc (yes, yes, I could put it in /usr/bin and be done with it… I didn’t want to).
Oh. And in answer to the question “Why?” Because it seemed like a thing to do.
Here’s my current “is this thing on?” worksheet. Pressing CMD-Return on any uncommented line executes that line:
List the five most recent posts from the selected blog
$MTSEND -q -L 5 -a “$BLOG”
Get latest five from default blog and make them ready for e-z export:
$MTSEND -q -L 5|grep ^|\ [1-9]|sed s/|//g |cut -b 1-5,28-|sed s/^\ /export\ POSTID\=\”/g|sed s/\ /\”\ #/2
Retrieve the post id and feed it to BBEdit
$MTSEND -q -G $POSTID > $HOME/.reedit && bbedit .reedit
Repost the contents of POSTID to the blog
cat $HOME/.reedit | $MTSEND -q -E $POSTID && echo “Done.”
Miscellaneous other things and under construction
List of all available blogs
$MTSEND -B pbowl