Sha256: 38a4d800bcf68452edebe98f59ff066a89f048d9d9b3ad8bdff75642fdc783e5

Contents?: true

Size: 752 Bytes

Versions: 814

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

814 entries across 814 versions & 1 rubygems

Version Path
rbbt-util-5.43.0 share/rbbt_commands/color
rbbt-util-5.42.0 share/rbbt_commands/color
rbbt-util-5.41.1 share/rbbt_commands/color
rbbt-util-5.41.0 share/rbbt_commands/color
rbbt-util-5.40.5 share/rbbt_commands/color
rbbt-util-5.40.4 share/rbbt_commands/color
rbbt-util-5.40.3 share/rbbt_commands/color
rbbt-util-5.40.0 share/rbbt_commands/color
rbbt-util-5.39.0 share/rbbt_commands/color
rbbt-util-5.38.1 share/rbbt_commands/color
rbbt-util-5.38.0 share/rbbt_commands/color
rbbt-util-5.37.16 share/rbbt_commands/color
rbbt-util-5.37.15 share/rbbt_commands/color
rbbt-util-5.37.14 share/rbbt_commands/color
rbbt-util-5.37.13 share/rbbt_commands/color
rbbt-util-5.37.12 share/rbbt_commands/color
rbbt-util-5.37.11 share/rbbt_commands/color
rbbt-util-5.37.10 share/rbbt_commands/color
rbbt-util-5.37.9 share/rbbt_commands/color
rbbt-util-5.37.8 share/rbbt_commands/color