Posts Tagged ‘auto-comment’

Auto Comment Block In TextMate

Monday, January 21st, 2008

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.


# Make comment / Undo comment
# by Schell Scivally
# @

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

Follow me on GitHub
Follow me on Google+
Follow me on Twitter