beforeRunningCommand nop command #!/usr/bin/env ruby doc = STDIN.read line = ENV['TM_LINE_NUMBER'].to_i line_index = ENV['TM_LINE_INDEX'].to_i if ENV.has_key? 'TM_INPUT_START_LINE' then line = ENV['TM_INPUT_START_LINE'].to_i line_index = ENV['TM_INPUT_START_LINE_INDEX'].to_i end before = /(.*\n){#{line-1}}.{#{line_index}}/.match(doc)[0] # remove all self-closing tags if ENV.has_key? 'TM_HTML_EMPTY_TAGS' then empty_tags = ENV['TM_HTML_EMPTY_TAGS'] before.gsub!(/<(#{empty_tags})\b[^>]*>|<[^>]+\/\s*>/i, '') end # remove all comments before.gsub!(/<!--.*?-->/m, '') # remove all erb-tags before.gsub!(/<%=.*?%>/m, '') stack = [ ] before.scan(/<\s*(\/)?\s*([\w:-]*)[^>]*>/) do |m| if m[0].nil? then stack << m[1] else until stack.empty? do close_tag = stack.pop break if close_tag == m[1] end end end if stack.empty? then %x{ osascript -e beep &>/dev/null & } else print "</#{stack.pop}>" end input document keyEquivalent ~@. name insert close tag (⌘⌥.) output afterSelectedText scope text.html.ruby.dryml uuid 21882A84-5563-48E6-AB53-6AA4C2C372BE