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.37.6 share/rbbt_commands/color
rbbt-util-5.37.4 share/rbbt_commands/color
rbbt-util-5.37.3 share/rbbt_commands/color
rbbt-util-5.37.1 share/rbbt_commands/color
rbbt-util-5.37.0 share/rbbt_commands/color
rbbt-util-5.36.0 share/rbbt_commands/color
rbbt-util-5.35.4 share/rbbt_commands/color
rbbt-util-5.35.3 share/rbbt_commands/color
rbbt-util-5.35.2 share/rbbt_commands/color
rbbt-util-5.35.1 share/rbbt_commands/color
rbbt-util-5.34.27 share/rbbt_commands/color
rbbt-util-5.34.26 share/rbbt_commands/color
rbbt-util-5.34.25 share/rbbt_commands/color
rbbt-util-5.34.24 share/rbbt_commands/color
rbbt-util-5.34.23 share/rbbt_commands/color
rbbt-util-5.34.22 share/rbbt_commands/color
rbbt-util-5.34.21 share/rbbt_commands/color
rbbt-util-5.34.20 share/rbbt_commands/color
rbbt-util-5.34.18 share/rbbt_commands/color
rbbt-util-5.34.17 share/rbbt_commands/color