diff options
Diffstat (limited to 'library/demos/browse')
-rw-r--r-- | library/demos/browse | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/library/demos/browse b/library/demos/browse index d3f55e3..cd9e09a 100644 --- a/library/demos/browse +++ b/library/demos/browse @@ -1,13 +1,13 @@ #!/bin/sh # the next line restarts using wish \ -exec wish "$0" "$@" +exec wish8.4 "$0" ${1+"$@"} || exec wish "$0" ${1+"$@"} # browse -- # This script generates a directory browser, which lists the working # directory and allows you to open files or subdirectories by # double-clicking. # -# RCS: @(#) $Id: browse,v 1.2 1998/09/14 18:23:27 stanton Exp $ +# RCS: @(#) $Id: browse,v 1.3 2001/10/29 16:42:20 dkf Exp $ # Create a scrollbar on the right side of the main window and a listbox # on the left side. @@ -24,29 +24,35 @@ wm minsize . 1 1 # the file is a regular file then the Mx editor is invoked to display # the file. +set browseScript [file join [pwd] $argv0] proc browse {dir file} { - global env + global env browseScript if {[string compare $dir "."] != 0} {set file $dir/$file} - if [file isdirectory $file] { - exec browse $file & - } else { - if [file isfile $file] { - if [info exists env(EDITOR)] { + switch [file type $file] { + directory { + exec [info nameofexecutable] $browseScript $file & + } + file { + if {[info exists env(EDITOR)]} { eval exec $env(EDITOR) $file & } else { exec xedit $file & } - } else { + } + default { puts stdout "\"$file\" isn't a directory or regular file" } } } -# Fill the listbox with a list of all the files in the directory (run -# the "ls" command to get that information). +# Fill the listbox with a list of all the files in the directory. -if $argc>0 {set dir [lindex $argv 0]} else {set dir "."} -foreach i [exec ls -a $dir] { +if {$argc>0} {set dir [lindex $argv 0]} else {set dir "."} +foreach i [lsort [glob * .* *.*]] { + if {[file type $i] eq "directory"} { + # Safe to do since it is still a directory. + append i / + } .list insert end $i } @@ -54,3 +60,7 @@ foreach i [exec ls -a $dir] { bind all <Control-c> {destroy .} bind .list <Double-Button-1> {foreach i [selection get] {browse $dir $i}} + +# Local Variables: +# mode: tcl +# End: |