Auto Comment Block In TextMate

If you haven’t heard of TextMate go check it out it’s sweet. It allows a helluva lot of automation and is damn near the only thing you need for development of any language [minus compilers]. I’m about ready to throw away my Flash CS3 IDE I got for free from my day job and shell out the 39 pounds to buy it [those of you who know me personally know I don't ever buy software].

So, here’s a little command I wrote in the form of a bash script [I think all textmate commands are bash scripts or cocoadialog thangs]. The script takes selected input and pads it with “/* */” if it isn’t already, effectively commenting the text or it strips the comment block. I don’t write shell scripts often, so I like it when I get one that’s really useful.

#!/bin/bash

#-------------------------------------------------------------------------
# Make comment / Undo comment
# by Schell Scivally
# @ efnx.com
#-------------------------------------------------------------------------

opening=`echo "$TM_SELECTED_TEXT" | awk 'BEGIN {nlines=0} /\/\*/ {nlines++} END {print nlines}'`
if [[ "$opening" == 0 ]];
    then
        echo -n "/*$TM_SELECTED_TEXT*/"
    else
        output=`echo "$TM_SELECTED_TEXT" | sed 's/\*\///g' | sed 's/\/\*//g'`
        echo -n "$output"
fi

Tags: , ,

One Response to “Auto Comment Block In TextMate”

  1. thank you

Leave a Reply


Follow me on GitHub
Follow me on Google+
Follow me on Twitter
Thrilling.
EFNX is proudly powered by WordPress
Entries (RSS) and Comments (RSS).