-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Joshua Uziel
committed
Mar 7, 2014
1 parent
a928298
commit af034d2
Showing
3 changed files
with
85 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
Code Grep and Vi Grepped | ||
cg, vg - tools for finding and modifying on keywords | ||
Joshua Uziel <[email protected]> - June 30, 1999 - version 1.2 | ||
Joshua Uziel <[email protected]> - July 7, 1999 - version 1.3 | ||
|
||
All too often I need to dig through source code. Where something | ||
is defined, used, what files, etc. There's a great tool for doing | ||
this from AT&T called "cscope" and a very alpha free clone of it | ||
called "cs" (that doesn't looks like it's being actively worked | ||
called "cs" (that doesn't look like it's being actively worked | ||
on) that does this. There are some alternatives... like ctags | ||
and etags for instance... but these only take you to where something | ||
is defined... not wherever it is used, which makes it frustrating | ||
|
@@ -43,11 +43,11 @@ recursively with something like "cg -r pattern *.c". Note that | |
running it like this creates a significant amount of overhead, so | ||
it's advisable to use the default search patterns when you can. | ||
|
||
The other script is called "vg" and opens a vi on what has been grepped | ||
(actually, it use "vi" or "vim"). So remember that count? All you | ||
have to do is run "vg count" and it'll fire off a vi in that file | ||
The other script is called "vg" and opens an editor on what has been | ||
grepped (most editors work). So remember that count? All you | ||
have to do is run "vg count" and it'll fire off a editor in that file | ||
and at that line number. So, in our example, running "vg 1" would | ||
open up a vi session on fs/ext2/acl.c at line 26. | ||
open up an editing session on fs/ext2/acl.c at line 26. | ||
|
||
It is the storing of the query in ~/.cglast that allows cg and vg | ||
to work together. Also, the reason for the ability to see the | ||
|
@@ -68,6 +68,20 @@ of time. Feel free to send me comments or suggestions... | |
---------------- | ||
REVISION HISTORY | ||
---------------- | ||
July 7, 1999 | ||
1.3 Same as the last version, except now colors are supported | ||
in cg. There are the options $BOLD, $BOLD_ALTERNATE and | ||
$COLOR to be set to 1 (on) or 0 (off) if you do or don't | ||
want these feature. $COLOR is needed for the $BOLD | ||
options, and really you should select only one or neither | ||
of the two $BOLD options. Colors only work when displaying | ||
straight to STDOUT. | ||
|
||
In vg, I've gotten rid of the $CGEDITOR variable and replaced | ||
it with the standard $EDITOR environment variable since I've | ||
found most editors to support the +number option. Also fixed | ||
a bug to give a clear error when the editor doesn't exist. | ||
|
||
June 30, 1999 | ||
1.2 - More changes to the cg script. Rather than simply print the | ||
logfile like previous versions, I actually attempt to make | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
#!/usr/bin/perl | ||
# cg - Code Grep - Copyright 1999 by Joshua Uziel <[email protected]> | ||
# This program is released under the GNU General Public License. | ||
# cg - cgvg version 1.2 | ||
# cg - cgvg version 1.3 | ||
# | ||
# Recursive Grep script that does a bit of extra work in adding a count | ||
# field and storing the data in a file. Run as if you were running | ||
|
@@ -16,6 +16,8 @@ | |
# adding the functionality that is generally missing from a developer's | ||
# toolbox. | ||
|
||
use POSIX; | ||
|
||
# Where to store the data | ||
$LOGFILE = "$ENV{'HOME'}/.cglast"; | ||
|
||
|
@@ -26,6 +28,37 @@ $EXCLUDE = "SCCS|RCS|tags|\.make\.state|Binary\ file"; | |
$SEARCH = "-name '*.[chs]' -o -name '*.cc' -o -name 'Make*' -o -name '*.pl' ", | ||
"-o -name '*.java' -o -name '*.*sh' -o -name '*.idl'"; | ||
|
||
# Set if you want colors (and your term supports it). This is required | ||
# for the $BOLD* options. | ||
$COLORS = 1; | ||
|
||
# Have everything printed in bold... 1 (yes) or 0 (no) only. This option | ||
# is overrided by $BOLD_ALTERNATE | ||
$BOLD = 0; | ||
|
||
# Make every other line bold. | ||
$BOLD_ALTERNATE = 1; | ||
|
||
# Defined colors | ||
%colors = ( 'black' => "30", | ||
'red' => "31", | ||
'green' => "32", | ||
'yellow' => "33", | ||
'blue' => "34", | ||
'magenta' => "35", | ||
'cyan' => "36", | ||
'white' => "37"); | ||
|
||
# Color for column # | ||
$c1 = $colors{'cyan'}; | ||
$c2 = $colors{'blue'}; | ||
$c3 = $colors{'red'}; | ||
$c4 = $colors{'green'}; | ||
|
||
# Check if stdout goes to a tty... can't do colors if we pipe to another | ||
# program like "more" or "less" or to a file. | ||
$COLORS = POSIX::isatty(fileno STDOUT) if ($COLORS); | ||
|
||
# Generate the log if an argument, and (using $count) add another field | ||
# to grep's output. | ||
if ($#ARGV+1) { | ||
|
@@ -152,11 +185,25 @@ if (($skip + 20) >= $COL) { | |
$mstr = $COL - $skip; | ||
|
||
$entries = $i; | ||
$BOLD = 0; | ||
|
||
for ($i=0; $i < $entries; $i++) { | ||
|
||
# Bold every other entry | ||
$BOLD = ($i % 2) if ($BOLD_ALTERNATE); | ||
|
||
# Print the properly justified first 3 fields. | ||
printf "%${mnum}s %-${mfile}s %${mline}s ", $rec[$i]->{num}, | ||
$rec[$i]->{file}, $rec[$i]->{line}; | ||
print "\e[$BOLD;${c1}m" if ($COLORS); | ||
printf "%${mnum}s ", $rec[$i]->{num}; | ||
print "\e[0m" if ($COLORS); | ||
|
||
print "\e[$BOLD;${c2}m" if ($COLORS); | ||
printf "%-${mfile}s ", $rec[$i]->{file}; | ||
print "\e[0m" if ($COLORS); | ||
|
||
print "\e[$BOLD;${c3}m" if ($COLORS); | ||
printf "%${mline}s ", $rec[$i]->{line}; | ||
print "\e[0m" if ($COLORS); | ||
|
||
# Newline only for "wrapmode". | ||
print "\n" if ($wrapmode); | ||
|
@@ -169,7 +216,9 @@ for ($i=0; $i < $entries; $i++) { | |
print " " x $skip if ($j || $wrapmode); | ||
|
||
# Print only $mstr character substring. | ||
print "\e[$BOLD;${c4}m" if ($COLORS); | ||
print substr $rec[$i]->{str}, ($j*$mstr), $mstr; | ||
print "\e[0m" if ($COLORS); | ||
print "\n"; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,29 @@ | ||
#!/usr/bin/perl | ||
# vg - Vi Grepped - Copyright 1999 by Joshua Uziel <[email protected]> | ||
# This program is released under the GNU General Public License. | ||
# vg - cgvg version 1.2 | ||
# vg - cgvg version 1.3 | ||
# | ||
# Helper script to go with cg for opening a vi session conveniently | ||
# Helper script to go with cg for opening a editor conveniently | ||
# with the correct file and line as shown in cg's log. Run this | ||
# with a single numerical argument (ie. "vg 3") to edit the desired | ||
# log entry. | ||
# | ||
# Note, unless modified, this script was designed to use vi(1) or vim(1), | ||
# but can easily be changed to whichever editor if you know the command- | ||
# line option for jumping to a specific line number. | ||
# This script seems to work fine with a number of editors, including | ||
# vi, vim, emacs, pico, joe, etc. (Despite it's name.) | ||
|
||
# File where the log is. | ||
$LOGFILE = "$ENV{'HOME'}/.cglast"; | ||
|
||
# Default editor to use. | ||
$EDITOR = "vi"; | ||
$EDITOR = "vim"; | ||
|
||
# Use the $CDEDITOR environment variable if it exists. | ||
$EDITOR = $ENV{'CGEDITOR'} if ($ENV{'CGEDITOR'}); | ||
# Use the $EDITOR environment variable if it exists. | ||
$EDITOR = $ENV{'EDITOR'} if ($ENV{'EDITOR'}); | ||
|
||
# We can't edit if the editor doesn't exist. | ||
`which $EDITOR`; | ||
$no_editor = $?; | ||
die "Error: Editor $EDITOR isn't in your path.\n" if ($no_editor); | ||
|
||
# We need one argument only, and it has to be a number. | ||
die "Error: Single argument needed.\n" unless ($#ARGV == 0); | ||
|
@@ -49,7 +53,7 @@ if ($PWD eq $path) { | |
foreach $line (<IN>) { | ||
($this, $file, $line) = (split(/:/, $line))[0,1,2]; | ||
|
||
# Change this to execute vi or vim... | ||
# Change this to execute the editor. | ||
exec "$EDITOR +$line $path$file" if ($num == $this); | ||
} | ||
|
||
|