Skip to content

Instantly share code, notes, and snippets.

@dakrone
Created February 1, 2010 06:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dakrone/291489 to your computer and use it in GitHub Desktop.
Save dakrone/291489 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby -w
# encoding: UTF-8
#
# A simply `p4 diff` output colorizer.
FILE_R = /^====\s+([\s\S]+)(#\d+) - ([\s\S]+) ====$/
POS_R = /^(\d+[ad]\d+)$/
OUT_R = /^< /
IN_R = /^> /
## Escape sequences for colors
## Misc
$RESET = "\033[0m"
$BOLD = "\033[1m"
$BLINK = "\033[5m"
## Foreground colors
$BLACK = "\033[30m"
$RED = "\033[31m"
$GREEN = "\033[32m"
$BROWN = "\033[33m"
$BLUE = "\033[34m"
$MAGENTA = "\033[35m"
$CYAN = "\033[36m"
$WHITE = "\033[37m"
$stdin.each_line do |line|
line.chomp!
if line =~ FILE_R
puts "#{$MAGENTA}" + line + "#{$RESET}"
elsif line =~ POS_R
puts "#{$CYAN}" + line + "#{$RESET}"
elsif line =~ OUT_R
puts "#{$RED}" + line + "#{$RESET}"
elsif line =~ IN_R
puts "#{$GREEN}" + line + "#{$RESET}"
else
puts line
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment