#!/usr/bin/perl # # MySQL query highlightÇϱâ # # by ÁÁÀºÁøÈ£(truefeel, http://coffeenix.net/ ) # 2008.11.24 # color $szColBk ="[;30m"; $szColBk1 ="[1;30m"; # black $szColRe ="[;31m"; $szColRe1 ="[1;31m"; # red $szColGr ="[;32m"; $szColGr1 ="[1;32m"; # green $szColYe ="[;33m"; $szColYe1 ="[1;33m"; # yellow $szColBl ="[;34m"; $szColBl1 ="[1;34m"; # blue $szColPu ="[;35m"; $szColPu1 ="[1;35m"; # magenta(purple) $szColCy ="[;36m"; $szColCy1 ="[1;36m"; # cyan $szColGy ="[;37m"; $szColWh ="[1;37m"; # white $szNormal="[;m"; # $szPattSel="SELECT"; $szPattChg="UPDATE|DELETE|INSERT|SET|COMMIT|ROLLBACK|CREATE|DROP|ALTER|SHOW"; $szPattMisc=" FROM | INTO| SET | VALUES"; $szPattWhere=" WHERE "; $szPatt="$szPattSel|$szPattChg"; # if ($#ARGV == 0) { $szPattWant="$ARGV[0]"; } # while() { chomp; next if /^[^ ]+[ ]*$/; if(/^($szPatt)/i) { if (defined $q) { $q=~ s/($szPattSel)/$szColGr$1$szNormal/gi; $q=~ s/($szPattChg)/$szColYe1$1$szNormal/gi; $q=~ s/($szPattMisc)/$szColYe$1$szNormal/gi; $q=~ s/($szPattWhere)/$szColCy1$1$szNormal/gi; $q=~ s/($szPattWant)/$szColRe1$1$szNormal/gi if ( $szPattWant ); print "$q\n"; } $q=$_; } else { $_ =~ s/^[ \t]+//; $q.=" $_"; } }