browse 1.7 KB

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