1 #!/usr/local/bin/wish -f
 
   3 # This script generates a directory browser, which lists the working
 
   4 # directory and allows you to open files or subdirectories by
 
   7 # Create a scrollbar on the right side of the main window and a listbox
 
  10 scrollbar .scroll -command ".list yview"
 
  11 listbox .list -yscroll ".scroll set" -relief raised -geometry 20x20
 
  12 pack append . .scroll {right filly} .list {left expand fill}
 
  14 # The procedure below is invoked to open a browser on a given file;  if the
 
  15 # file is a directory then another instance of this program is invoked; if
 
  16 # the file is a regular file then the Mx editor is invoked to display
 
  19 proc browse {dir file} {
 
  20     if {[string compare $dir "."] != 0} {set file $dir/$file}
 
  21     if [file isdirectory $file] {
 
  24         if [file isfile $file] {
 
  27             puts stdout "\"$file\" isn't a directory or regular file"
 
  32 # Fill the listbox with a list of all the files in the directory (run
 
  33 # the "ls" command to get that information).
 
  35 if $argc>0 {set dir [lindex $argv 0]} else {set dir "."}
 
  36 foreach i [exec ls -a $dir] {
 
  40 # Set up bindings for the browser.
 
  42 bind .list <Control-q> {destroy .}
 
  43 bind .list <Control-c> {destroy .}
 
  45 bind .list <Double-Button-1> {foreach i [selection get] {browse $dir $i}}