Updated 2013-03-05 01:59:17 by pooryorick

Summary  edit

Richard Suchenwirth 2003-02-19: The following version of a little file searcher has been hand-tuned to look good, and work well, on the iPAQ:

Description  edit

proc ui {} {
    entry     .e -bg white -textvar search
    bind .e <Return> {search $search .t}
    bind .e <Up>     {set search ""}
    button .x -text X -command exit -padx 0 -width 1 ;# explicit close button
    text      .t -width 43 -height 15 -yscrollcommand ".y set" -bg white -wrap word
    scrollbar .y -command ".t yview"

    grid .e .x -sticky ew
    grid .t .y -sticky news
    grid columnconfig . 0 -weight 1
    grid rowconfig . 1 -weight 1
}
proc search {re w} {
    global file
    $w delete 1.0 end
    set n 0
    set fp [open $file]
    while {[gets $fp line]>=0} {
        if {[regexp -nocase -- $re $line]} {
            $w insert end $line\n
            update idletasks
            incr n
        }
    }
    close $fp
    $w insert end "Found $n lines"
    $w see end
}
ui
update idletasks ;# needed so the dialog is not killed
focus .e
wm geometry . +0+0
set file [lindex $argv 0]
if {$file == ""} {set file [tk_getOpenFile]}
wm title . [file tail $file]

See Also  edit

incrFilter
A grep-like utility