Skip to content

Instantly share code, notes, and snippets.

@robballou
Created September 8, 2010 21:18
Show Gist options
  • Save robballou/570855 to your computer and use it in GitHub Desktop.
Save robballou/570855 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
#
# Textmate item to increment all numbers in a selection
#
# If you have:
#
# line1
# line1
# line1
#
# You can run this to get:
#
# line1
# line2
# line3
#
text = ENV['TM_SELECTED_TEXT']
starting_num = nil
current_num = nil
text.each do |line|
numbers = line.scan(/\d+/)
if starting_num == nil
starting_num = numbers[0].to_i
current_num = numbers[0].to_i
else
current_num = current_num + 1
line = line.gsub(starting_num.to_s, current_num.to_s)
end
puts line
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment