#!/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('')) { |f, t| m[f] = "\e[01;31m\e[K#{t}\e[m\e[K" } while c = STDIN.getc STDOUT.print(m[c] || c) end