Difference between revisions of "F"

From Ghoulwiki
Jump to: navigation, search
 
(4 intermediate revisions by the same user not shown)
Line 7: Line 7:
  
  
<pre><nowiki>
+
<pre><nowiki>#!/usr/bin/php5
#!/usr/bin/php5
 
 
<?php
 
<?php
  
Line 23: Line 22:
 
$searchroot = getcwd();
 
$searchroot = getcwd();
 
if ($searchroot == "/home/ghoul/") exit("wrong search dir\n");
 
if ($searchroot == "/home/ghoul/") exit("wrong search dir\n");
foreach ($gBasePaths as $basepath) if (strpos($cwd,$basepath) === 0) $searchroot = $basepath;
+
foreach ($gBasePaths as $basepath) if (substr($searchroot,0,strlen($basepath)) == $basepath) $searchroot = $basepath;
  
 
// -I : no binary files
 
// -I : no binary files
$cmd = 'grep -inr -I --include='.escapeshellarg($ext).' '.escapeshellarg($search).' '.$searchroot;
+
// -n : print line number
 +
// -r : recurse to dirs
 +
// -i : ignore case
 +
$cmd = 'grep -Iinr ';
 +
$cmd .= '--include='.escapeshellarg($ext).' ';
 +
$cmd .= '--exclude-dir='.escapeshellarg(".svn").' ';
 +
$cmd .= '--exclude-dir='.escapeshellarg("lugre").' ';
 +
$cmd .= escapeshellarg($search).' ';
 +
$cmd .= $searchroot.' ';
 +
$cmd .= '| tr -s " \t"';
 
//~ echo $cmd."\n";
 
//~ echo $cmd."\n";
 
passthru($cmd);
 
passthru($cmd);
Line 41: Line 49:
  
 
$gRedirectLists = array( // helpful for plugin folders
 
$gRedirectLists = array( // helpful for plugin folders
array(
 
"/cavern/wwwroot/scitestuff/robscite/scite/src",
 
"/cavern/wwwroot/scitestuff/robscite/scite/gtk",
 
),
 
array(
 
"/cavern/wwwroot/scitestuff/robscite",
 
"/cavern/wwwroot/scitestuff/robscite/scite",
 
"/cavern/wwwroot/scitestuff/robscite/scite/src",
 
"/cavern/wwwroot/scitestuff/robscite/scite/gtk",
 
),
 
array(
 
"/cavern/wwwroot/zw05",
 
"/cavern/wwwroot/zw05/info",
 
),
 
 
array(
 
array(
 
"/cavern/wwwroot/sfz/writable/plugins",
 
"/cavern/wwwroot/sfz/writable/plugins",
Line 64: Line 58:
 
"/cavern/wwwroot/sfz/mylugre/src",
 
"/cavern/wwwroot/sfz/mylugre/src",
 
"/cavern/wwwroot/sfz/mylugre/include",
 
"/cavern/wwwroot/sfz/mylugre/include",
),
 
array(
 
"/cavern/wwwroot/localsfz/data/plugins",
 
"/cavern/wwwroot/localsfz/data/lua",
 
"/cavern/wwwroot/localsfz/data/system",
 
"/cavern/wwwroot/localsfz/src",
 
"/cavern/wwwroot/localsfz/include",
 
"/cavern/wwwroot/localsfz/mylugre/lua",
 
"/cavern/wwwroot/localsfz/mylugre/src",
 
"/cavern/wwwroot/localsfz/mylugre/include",
 
),
 
array(
 
"/cavern/wwwroot/iris/iris_ogre3d/data/lua/gui",
 
"/cavern/wwwroot/iris/iris_ogre3d/data/lua/net",
 
"/cavern/wwwroot/iris/iris_ogre3d/data/lua/obj",
 
"/cavern/wwwroot/iris/iris_ogre3d/data/lua",
 
"/cavern/wwwroot/iris/iris_ogre3d/src",
 
"/cavern/wwwroot/iris/iris_ogre3d/include",
 
"/cavern/wwwroot/iris/iris_ogre3d/mylugre/lua",
 
"/cavern/wwwroot/iris/iris_ogre3d/mylugre/src",
 
"/cavern/wwwroot/iris/iris_ogre3d/mylugre/include",
 
),
 
array(
 
"/cavern/wwwroot/iris/knut/data/lua/gui",
 
"/cavern/wwwroot/iris/knut/data/lua/net",
 
"/cavern/wwwroot/iris/knut/data/lua/obj",
 
"/cavern/wwwroot/iris/knut/data/lua",
 
"/cavern/wwwroot/iris/knut/src",
 
"/cavern/wwwroot/iris/knut/include",
 
 
),
 
),
 
);
 
);
 
 
  
 
$curworkingdir = getcwd();
 
$curworkingdir = getcwd();
Line 124: Line 87:
 
system('grep -inr --include "*'.$argv[2].'" "'.$argv[1].'" '.$dir.' | tr -s " \t"');
 
system('grep -inr --include "*'.$argv[2].'" "'.$argv[1].'" '.$dir.' | tr -s " \t"');
 
}
 
}
 
/*
 
 
 
if ($argc != 2 || in_array($argv[1], array('--help', '-help', '-h', '-?'))) {    $argv[0] is programname
 
 
 
$path = "/cavern/mukke/Sonata Arctica/The Collection/";
 
function dirfilelist ($path) {
 
// plakat/  last slash is important !
 
$list = array();
 
if (!file_exists($path)) return $list;
 
$dir = opendir($path);
 
if (!$dir) return $list;
 
while (($file = readdir($dir)) !== false)
 
if ($file != "." && $file != ".." && is_file($path.$file)) $list[] = $file;
 
closedir($dir);
 
return $list;
 
}
 
 
$path = $path."/";
 
$arr = dirfilelist($path);
 
foreach ($arr as $filepath) {
 
$a = strtr($filepath,array(" "=>"_","-"=>"_","'"=>"","("=>"_",")"=>"_"));
 
echo $a." : $filepath\n";
 
rename($path.$filepath,$path.$a);
 
}
 
 
function MyCommand ($cmd) {
 
echo $cmd." : ";
 
echo exec($cmd)."\n";
 
sleep(2);
 
}
 
*/
 
 
 
/*
 
/*
 
#!/bin/sh
 
#!/bin/sh

Latest revision as of 22:41, 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 ';
$cmd .= '--include='.escapeshellarg($ext).' ';
$cmd .= '--exclude-dir='.escapeshellarg(".svn").' ';
$cmd .= '--exclude-dir='.escapeshellarg("lugre").' ';
$cmd .= escapeshellarg($search).' ';
$cmd .= $searchroot.' ';
$cmd .= '| 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
*/
?>