#!/usr/bin/env ruby
#
# ctr FROM TO - colored tr
#
# contrary to tr(1), this deletes non-existing entries in TO, and
# doesn't repeat the last.  ranges are not supported.

m = {}
ARGV[0].to_s.split("").zip(ARGV[1].to_s.split("")) do |f, t|
  m[f] = "\e[01;31m\e[K#{t}\e[m\e[K"
end

while c = $stdin.getc
  $stdout.print(m[c] || c)
end
