Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- File.open(ARGV[0]) { |input|
- File.open(ARGV[0] + '.sorted', 'w') { |out|
- sorting = false
- lists = {}
- while line = input.gets
- prefix = ''
- if sorting
- prefix = line.sub(/[^\/]*$/, '')
- lists[prefix] = [] if lists[prefix].nil?
- end
- list = lists[prefix]
- if sorting and line !~ /\]/
- list << line.chomp
- elsif line =~ /\]/
- all = []
- lists.keys.sort.each { |key|
- list = lists[key]
- list.sort!
- list.map! { |file| file !~ /,$/ ? file + ',' : file }
- all += list
- }
- # all[-1].sub!(/,$/, '') unless all.empty?
- all.each { |file| out.puts file }
- lists.clear
- sorting = false
- elsif line =~ /files.*\[/
- out.puts line
- sorting = true
- end
- out.puts line unless sorting
- end
- }
- }
- File.rename(ARGV[0] + '.sorted', ARGV[0])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement