Last active
August 29, 2015 14:18
-
-
Save michaelfward/00ed4a01b56b3f6b8889 to your computer and use it in GitHub Desktop.
ruby script to adjust lines a through b (i made it for when i copy and paste large chunks of code but don't want to fix my indentations. keep a uniform pattern throughout, and voila)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#programmed by michael ward | |
#[email protected] | |
def adjustline(line, off) | |
str = "" | |
1.upto(off) {|x| str << " "} | |
str << line | |
str | |
end | |
def getfile_withlines(fd,a,b,off) | |
num = 0 | |
nl = [] | |
fd.each_line do |line| | |
num += 1 | |
if num >= a && num <= b | |
line = adjustline(line, off) | |
nl.push(line) | |
else | |
nl.push(line) | |
end | |
end | |
nl | |
end | |
def write(content, path) | |
fdd = File.open(path, "w") | |
content.each{|str| fdd.write(str)} | |
end | |
def usage | |
puts "movefile.rb file startline endline offset" | |
exit | |
end | |
usage unless ARGV.length == 4 | |
path, startline, endline, offset = ARGV[0..3] | |
fd = File.open(path, "r") | |
nw = getfile_withlines(fd, startline.to_i, endline.to_i, offset.to_i) | |
write(nw, path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment