Difference between revisions of "F"
From Ghoulwiki
Ghoulsblade (talk | contribs) |
Ghoulsblade (talk | contribs) |
||
Line 43: | Line 43: | ||
$gRedirectLists = array( // helpful for plugin folders | $gRedirectLists = array( // helpful for plugin folders | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
array( | array( | ||
"/cavern/wwwroot/sfz/writable/plugins", | "/cavern/wwwroot/sfz/writable/plugins", | ||
Line 66: | Line 52: | ||
"/cavern/wwwroot/sfz/mylugre/src", | "/cavern/wwwroot/sfz/mylugre/src", | ||
"/cavern/wwwroot/sfz/mylugre/include", | "/cavern/wwwroot/sfz/mylugre/include", | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
), | ), | ||
); | ); | ||
− | |||
− | |||
$curworkingdir = getcwd(); | $curworkingdir = getcwd(); | ||
Line 126: | Line 81: | ||
system('grep -inr --include "*'.$argv[2].'" "'.$argv[1].'" '.$dir.' | tr -s " \t"'); | system('grep -inr --include "*'.$argv[2].'" "'.$argv[1].'" '.$dir.' | tr -s " \t"'); | ||
} | } | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
/* | /* | ||
#!/bin/sh | #!/bin/sh |
Revision as of 19:12, 12 July 2008
put this in /bin or so so that you can use it like
f something .lua
in all your favourite dirs.
For optimal results you have to adjust the project paths, otherwise it will just search in all subdirs of the current working dir, so if you search in src/ you'll miss include/ etc...
#!/usr/bin/php5 <?php // your project dirs $gBasePaths = array( //~ "/cavern/code/iris", "/cavern/code/sfz", "/usr/src/ogre", ); $search = $argv[1]; $ext = "*".$argv[2]; $searchroot = getcwd(); if ($searchroot == "/home/ghoul/") exit("wrong search dir\n"); foreach ($gBasePaths as $basepath) if (substr($searchroot,0,strlen($basepath)) == $basepath) $searchroot = $basepath; // -I : no binary files // -n : print line number // -r : recurse to dirs // -i : ignore case $cmd = 'grep -Iinr --include='.escapeshellarg($ext).' --exclude-dir='.escapeshellarg(".svn").' '.escapeshellarg($search).' '.$searchroot.' | tr -s " \t"'; //~ echo $cmd."\n"; passthru($cmd); ?>
OLD VERSION
#!/usr/bin/php <?php $gRedirectLists = array( // helpful for plugin folders array( "/cavern/wwwroot/sfz/writable/plugins", "/cavern/wwwroot/sfz/writable/system", "/cavern/wwwroot/sfz/lua", "/cavern/wwwroot/sfz/src", "/cavern/wwwroot/sfz/include", "/cavern/wwwroot/sfz/mylugre/lua", "/cavern/wwwroot/sfz/mylugre/src", "/cavern/wwwroot/sfz/mylugre/include", ), ); $curworkingdir = getcwd(); if (in_array($curworkingdir,array("/home/ghoul","/home/ghoul/Desktop"))) die("wrong working dir\n"); $dirlist = array(); $dirlist[] = $curworkingdir; foreach ($gRedirectLists as $list) if (in_array($curworkingdir,$list)) foreach ($list as $dir) $dirlist[] = $dir; $dirlist = array_unique($dirlist); function does_not_have_parent($curdir) { global $dirlist; $curlen = strlen($curdir); foreach ($dirlist as $dir) { $len = strlen($dir); if ($len < $curlen && strncmp($dir,$curdir,$len) == 0) return false; // parent found } return true; } $dirlist = array_filter($dirlist, "does_not_have_parent"); if ($argc <= 2) { echo "ERROR: missing file-name-pattern, if you really want to search in all files, please specify * as path-part explicitly\n"; // system('grep -inr "'.$argv[1].'" '.$dir.' | tr -s " \t"'); die; } foreach ($dirlist as $dir) { system('grep -inr --include "*'.$argv[2].'" "'.$argv[1].'" '.$dir.' | tr -s " \t"'); } /* #!/bin/sh # tr -s " \t" fasst aufeinanderfolgende spaces und tabs zusammen # less -S schneidet überlange zeilen ab # inr : ignore-case , line-numbers , recursive # grep $2: wenn als $2 ".php" übergeben wird, werden nur zeilen dargestellt die mit .php:zeilennummer: anfangen. if [ $# -gt 1 ] #then fgrep -inr "$1" . | grep "$2:" | tr -s " \t" #else fgrep -inr "$1" . | tr -s " \t" then grep -inr --include "*$2" "$1" . | tr -s " \t" else grep -inr "$1" . | tr -s " \t" fi */ ?>