Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | #!/bin/sh |
2 | # the next line restarts using wish \ | |
3 | exec wish8.4 "$0" ${1+"$@"} | |
4 | ||
5 | # browse -- | |
6 | # This script generates a directory browser, which lists the working | |
7 | # directory and allows you to open files or subdirectories by | |
8 | # double-clicking. | |
9 | # | |
10 | # RCS: @(#) $Id: browse,v 1.4 2001/11/05 10:13:53 dkf Exp $ | |
11 | ||
12 | # Create a scrollbar on the right side of the main window and a listbox | |
13 | # on the left side. | |
14 | ||
15 | scrollbar .scroll -command ".list yview" | |
16 | pack .scroll -side right -fill y | |
17 | listbox .list -yscroll ".scroll set" -relief sunken -width 20 -height 20 \ | |
18 | -setgrid yes | |
19 | pack .list -side left -fill both -expand yes | |
20 | wm minsize . 1 1 | |
21 | ||
22 | # The procedure below is invoked to open a browser on a given file; if the | |
23 | # file is a directory then another instance of this program is invoked; if | |
24 | # the file is a regular file then the Mx editor is invoked to display | |
25 | # the file. | |
26 | ||
27 | set browseScript [file join [pwd] $argv0] | |
28 | proc browse {dir file} { | |
29 | global env browseScript | |
30 | if {[string compare $dir "."] != 0} {set file $dir/$file} | |
31 | switch [file type $file] { | |
32 | directory { | |
33 | exec [info nameofexecutable] $browseScript $file & | |
34 | } | |
35 | file { | |
36 | if {[info exists env(EDITOR)]} { | |
37 | eval exec $env(EDITOR) $file & | |
38 | } else { | |
39 | exec xedit $file & | |
40 | } | |
41 | } | |
42 | default { | |
43 | puts stdout "\"$file\" isn't a directory or regular file" | |
44 | } | |
45 | } | |
46 | } | |
47 | ||
48 | # Fill the listbox with a list of all the files in the directory. | |
49 | ||
50 | if {$argc>0} {set dir [lindex $argv 0]} else {set dir "."} | |
51 | foreach i [lsort [glob * .* *.*]] { | |
52 | if {[file type $i] eq "directory"} { | |
53 | # Safe to do since it is still a directory. | |
54 | append i / | |
55 | } | |
56 | .list insert end $i | |
57 | } | |
58 | ||
59 | # Set up bindings for the browser. | |
60 | ||
61 | bind all <Control-c> {destroy .} | |
62 | bind .list <Double-Button-1> {foreach i [selection get] {browse $dir $i}} | |
63 | ||
64 | # Local Variables: | |
65 | # mode: tcl | |
66 | # End: |