Find In File — File Browser
FindInFilev0.3 / FindInFilev0.3 / fif / fif.mrc
fif.mrc — 6.77 KB — Download this file
/*
* Find In File v0.3
* Searches for a [regex] pattern inside all files
* matching <filemask> in <directory> going <depth> folders deep.
* LtGuide - 31 Oct 2004
*
* v0.3 fixed depth (some sorta fluke with certain filemasks)
* initial dialog focus
* v0.2 added config dialog
* v0.1 initial release with file handling,
* converted from simple $read alias with no settings
*/
/*
* How to use:
* Load script into mIRC (at least v6.1x)
* using, for example, `/load -rs fif.mrc'
* or `/load -rs "d:\unzipped files\fif\fif.mrc"'
* Accept initialization warning (or not, doesn't matter)
* The `/fif' command opens the FIF window and prints what you do.
*
* Hint: You can double-click on the file paths that are printed as having
* matched your search. They will open in your default editor.
*
* To unload, select Unload from Menubar or Status Window,
* select Unload from inside the Remote Editor (while looking at fif.mrc),
* or `/unload -rs fif.mrc'
* Upon unloading the script, the FIF window will be closed and your
* directory and file mask histories (from config dialog) will be deleted.
*/
/*
* /fif [-r] [pattern]
*/
alias fif {
fif.default
var %dir = $gettok($hget(fif,dir.0),2-,32)
var %depth = $hget(fif,depth)
var %filemask = $gettok($hget(fif,filemask.0),2-,32)
if (!$window(@fif)) window -nek0 @fif
if ($1) {
window -n @fif
if ($1 == -r) && (!$2) echo @fif error: specified regex search, but no search terms
else {
hadd fif switch -w
hadd fif seek $1-
if ($1 == -r) {
hadd fif switch -r
hadd fif seek $2-
}
echo @fif $chr(2)
echo @fif searching all %filemask files in $+(",%dir,") $iif(%depth,and %depth $fif.s(level,%depth) deep) ...
var %fopen = $fopen(0)
if (%depth) var %c = $findfile(%dir,%filemask,0,%depth,fif.scan " $+ $1-")
else var %c = $findfile(%dir,%filemask,0,fif.scan " $+ $1-")
echo @fif $chr(2)
echo @fif %c file $+ $iif(%c != 1,s) scanned $iif($fopen(0) > %fopen,( $+ $ifmatch partial $fif.s(listing,$ifmatch) $+ ; use narrower search terms))
.fclose fif/*
hdel fif switch
hdel fif seek
}
window -a @fif
}
elseif ($active != @fif) {
if (!$line(@fif,0)) {
echo @fif Type in your search terms and press enter. To use regex, -r must be the first word you type.
echo @fif Right-click with your mouse to see options. Config option may also be initiated by /fif.config (or /.fif.config for the dialog).
echo @fif config setting: search all %filemask files in $+(",%dir,") $iif(%depth,and %depth $fif.s(level,%depth) deep)
}
window -a @fif
}
}
/*
* fif.scan <filename>
*/
alias -l fif.scan {
var %fh = fif/ $+ $replace($1-,$chr(32),|)
var %seek = $hget(fif,switch) %fh $hget(fif,seek)
.fopen %fh $1-
.fseek %seek
if (!$feof) {
echo @fif $chr(2)
echo -c highlight @fif $+([,$nopath($1-),]) $mid($1-,2,-1)
while (!$feof) {
echo @fif $fread(%fh)
.fseek %seek
}
}
.fclose %fh
}
/*
* /fif.config > [dir] > [depth] > [filemask]
*/
alias fif.config {
if (!$show) dialog $iif($dialog(fif),-v,-m) fif fif
else {
fif
if ($1) {
tokenize 62 $1-
fif.latest dir $gettok($1,1-,32)
if ($gettok($2,1-,32) != $null) hadd fif depth $2
fif.latest filemask $gettok($3,1-,32)
var %dir = $gettok($hget(fif,dir.0),2-,32)
var %depth = $hget(fif,depth)
var %filemask = $gettok($hget(fif,filemask.0),2-,32)
echo @fif config: search all %filemask files in $+(",%dir,") $iif(%depth,and $ifmatch $fif.s(level,$ifmatch) deep)
}
else echo @fif /fif.config > [dir] > [depth] > [filemask]
if ($active != @fif) window -a @fif
}
}
/*
* fif.latest <'dir'|'filemask'> <dir|filemask>
*/
alias -l fif.latest {
if ($2-) && ($1- != $hget(fif,$1. $+ 0)) {
var %l = $gettok($hfind(fif,$1-,1).data,2,46)
if (!%l) %l = 9
while (%l > 0) {
if ($hget(fif,$1. $+ $calc(%l - 1))) { hadd fif $1. $+ %l $ifmatch }
dec %l
}
hadd fif $1. $+ 0 $1-
}
}
/*
* fif.s <word> <N>
*/
alias -l fif.s return $1 $+ $iif($2 != 1,s)
/*
* fif.dir
*/
alias -l fif.dir return " $+ $scriptdirfif.conf"
/*
* fif.default
*/
alias -l fif.default {
if (!$hget(fif)) {
hmake fif 3
if ($isfile($fif.dir)) hload -i fif $fif.dir fif
}
if (!$hget(fif,dir.0)) hadd fif dir.0 dir $mircdir
if ($hget(fif,depth) == $null) hadd fif depth 0
if (!$hget(fif,filemask.0)) hadd fif filemask.0 filemask *.*
}
/*
* fif.dialog.init
*/
alias -l fif.dialog.init {
fif.default
fif.dialog.latest dir 3
did -a fif 5 $hget(fif,depth)
fif.dialog.latest filemask 8
}
/*
* fif.dialog.latest <'dir'|'filemask'> <dialogid>
*/
alias fif.dialog.latest {
var %l = 0
while ($hget(fif,$1. $+ %l)) {
did -a fif $2 $gettok($ifmatch,2-,32)
inc %l
}
did -c fif $2 1
}
menu @fif {
Clear:clear @fif
-
Config:.fif.config
-
Close:window -c @fif
}
menu menubar,status {
Find In File
.$iif($window(@fif),Close):window -c @fif
.$iif(!$window(@fif),Open):fif
.-
.$iif($line(@fif,0),Clear):clear @fif
.-
.Config:.fif.config
.-
.Unload:if ($input(Are you sure you want to unload Find In File?,8,Find In File)) unload -rs $+(",$script,")
}
on *:LOAD:{
if ($version < 6.1) echo -s Find In File requires mIRC v6.1x (file handling)
echo -s Find In File options in Menubar and Status Window (/fif)
}
on *:UNLOAD:{
window -c @fif
hfree -w fif
if ($isfile($fif.dir)) .remove $fif.dir
}
on *:EXIT:{
if ($hget(fif)) hsave -oi fif $fif.dir fif
}
on ^*:HOTLINK:*:@fif:{
if ([*] *:\* iswm $hotline) && ([*] !iswm $1) return
halt
}
on *:HOTLINK:*:@fif:{ run $+(",$gettok($hotline,2-,32),") }
on *:INPUT:@fif:{
if (/* !iswm $1) || ($ctrlenter) { fif $1- }
}
on *:DIALOG:fif:INIT:0:{
fif.dialog.init
did -f fif 10
}
on *:DIALOG:fif:SCLICK:2:{
fif.default
did -ic fif 3 1 $$sdir($iif($did(3),$ifmatch,$gettok($hget(fif,dir.0),2-,32)),Select base directory for searching)
}
on *:DIALOG:fif:SCLICK:9:{
beep
fif.config > $did(3) > $did(5) > $did(8)
did -r fif 3,5,8
fif.dialog.init
}
dialog -l fif {
title "Find In File"
size -1 -1 134 56
option dbu
text "The directory to start searching from:", 1, 2 2 94 6
button ">>", 2, 120 2 12 6
combo 3, 2 10 130 46, size edit vsbar drop
text "Search this many folders deep into the directory:", 4, 2 22 116 6
edit "", 5, 122 22 10 8
text "Files masks to look at:", 6, 2 32 56 6
text "(supports wildcards: * and ?)", 7, 2 38 70 6
combo 8, 76 32 56 46, size edit vsbar drop
button "Apply", 9, 84 46 22 8
button "Close", 10, 108 46 22 8, cancel
}