Sha256: 38a4d800bcf68452edebe98f59ff066a89f048d9d9b3ad8bdff75642fdc783e5

Contents?: true

Size: 752 Bytes

Versions: 816

Compression:

Stored size: 752 Bytes

Contents

#!/usr/bin/env ruby

require 'rbbt-util'
require 'rbbt/util/simpleopt'

$0 = "rbbt #{$previous_commands*""} #{ File.basename(__FILE__) }" if $previous_commands

options = SOPT.setup <<EOF
Matches text and colors it.

$ rbbt color <file|-> (<color> <pattern>)+

Use - to read from STDIN. Example: `rbbt color - red "/.*rbbt.*/"`

-h--help Print help

EOF
rbbt_usage and exit 0 if options[:help]

file, *rest = ARGV

if file == '-'
  text = STDIN.read
else
  text = Open.read(file)
end

while rest.any?
  color = rest.shift
  pattern = rest.shift
  color = color.to_sym
  if pattern =~ /^\/(.*)\/$/
    text.gsub!(Regexp.compile($1)){|match| Log.color color, match }
  else
    text.gsub!(pattern){|match| Log.color color, match }
  end
end

puts text


Version data entries

816 entries across 816 versions & 1 rubygems

Version Path
rbbt-util-5.32.28 share/rbbt_commands/color
rbbt-util-5.32.27 share/rbbt_commands/color
rbbt-util-5.32.26 share/rbbt_commands/color
rbbt-util-5.32.25 share/rbbt_commands/color
rbbt-util-5.32.24 share/rbbt_commands/color
rbbt-util-5.32.23 share/rbbt_commands/color
rbbt-util-5.32.22 share/rbbt_commands/color
rbbt-util-5.32.21 share/rbbt_commands/color
rbbt-util-5.32.20 share/rbbt_commands/color
rbbt-util-5.32.18 share/rbbt_commands/color
rbbt-util-5.32.17 share/rbbt_commands/color
rbbt-util-5.32.16 share/rbbt_commands/color
rbbt-util-5.32.15 share/rbbt_commands/color
rbbt-util-5.32.13 share/rbbt_commands/color
rbbt-util-5.32.12 share/rbbt_commands/color
rbbt-util-5.32.11 share/rbbt_commands/color
rbbt-util-5.32.10 share/rbbt_commands/color
rbbt-util-5.32.9 share/rbbt_commands/color
rbbt-util-5.32.7 share/rbbt_commands/color
rbbt-util-5.32.6 share/rbbt_commands/color