Skip to content

Instantly share code, notes, and snippets.

@nocd5
Created January 22, 2015 15:39
Show Gist options
  • Select an option

  • Save nocd5/a0931bde6e5901855028 to your computer and use it in GitHub Desktop.

Select an option

Save nocd5/a0931bde6e5901855028 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# command! -nargs=* -range AlignEqual <line1>,<line2>!ruby C:\Tools\bin\runtime\AlignEqual.rb <args>
Pattern = "(.*?)(#{ARGV.size.zero? ? "=" : ARGV[0]})(.*\n)"
@Lines = STDIN.read
# get max length
$MaxLen = 0
@Lines.each_line{ |line|
$MaxLen = [$1.length, $MaxLen].max if (line =~ /#{Pattern}/)
}
# put lines
@Lines.each_line{ |line|
if (line =~ /#{Pattern}/)
puts $1 + " "*($MaxLen - $1.length) + $2 + $3
else
puts line
end
}
# vim: et ts=2 sw=2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment