Custom Textmate Commands
Textmate is a pretty decent editor for OSX. I’m not in love with it, but I use it frequently.
There is a plethora of plugins for Textmate to ease editing in different contexts, but sometimes you want to hack you’re own commands.
For small scripting tasks, I tend to continue to use ruby. So I enjoy it when I can continue using it for the commands.
You can typically use this shell for a ruby command, and your printed output gets replaced within Textmate:
#!/usr/bin/env ruby
$: << ENV['TM_SUPPORT_PATH'] + '/lib'
input_from_tm = STDIN.read
puts "hello world!"
Here is an example of code block toggling for Markdown.
#!/usr/bin/env ruby
$: << ENV['TM_SUPPORT_PATH'] + '/lib'
s = STDIN.read
ends_with_newline = s != s.chomp
lines = s.split("\n")
lines.each_with_index do |s, index|
s =~ /^(\t)?(.*)/
if $1
print "#{$2}"
else
print "\t#{$2}"
end
print "\n" if index != lines.size - 1
end
print "\n" if ends_with_newline
And a screenshot to include the Textmate command options: