From 0dde5917fb5135ee3601383c29ffc0490071ea9d Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 14 Dec 2015 04:48:01 +0000 Subject: dtas-tl: simplify existing addtail/addhead while we're at it No need to keep track of added track IDs when we can walk the array backwards to insert in the correct order. Also, fix a stupid (probably?) typo in the "addhead" implementation, too. I've known about Array#reverse_each for a while... --- bin/dtas-tl | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'bin/dtas-tl') diff --git a/bin/dtas-tl b/bin/dtas-tl index b682e2b..e375ff2 100755 --- a/bin/dtas-tl +++ b/bin/dtas-tl @@ -105,7 +105,7 @@ when "cat" end when "addhead" ARGV.shift - ARGV.reverse.each do |path| + ARGV.reverse_each do |path| path = File.expand_path(path) res = c.req(%W(tl add #{path})) print "#{path} #{res}\n" @@ -114,13 +114,11 @@ when "addtail" ARGV.shift track_ids = get_track_ids(c) last_id = track_ids.pop - ARGV.each do |path| + ARGV.reverse_each do |path| path = File.expand_path(path) req = %W(tl add #{path}) - req << last_id.to_s if last_id res = c.req(req) print "#{path} #{res}\n" - last_id = res if res =~ /\A\d+\z/ end when "reto" fixed = ARGV.delete("-F") -- cgit v1.2.3-24-ge0c7