Browse Source

Fix ./ to handle globs, change ./ & ../ to return dict with keys location dircount filecount

master
Julian Noble 1 year ago
parent
commit
11833b0e53
  1. 61
      src/modules/punk-0.1.tm

61
src/modules/punk-0.1.tm

@ -4123,10 +4123,9 @@ namespace eval punk {
set files [lsort $files] ;#todo natsort set files [lsort $files] ;#todo natsort
return [list dirs $dirs vfs $vfs files $files location $location] return [list dirs $dirs vfs $vfs files $files location $location]
} }
proc dirfiles {{glob ""}} {
proc dirfiles_dict_as_lines {contents} {
package require overtype package require overtype
set contents [dirfiles_dict $glob]
set dirs [dict get $contents dirs] set dirs [dict get $contents dirs]
set files [dict get $contents files] set files [dict get $contents files]
set vfs [dict get $contents vfs] set vfs [dict get $contents vfs]
@ -4148,6 +4147,11 @@ namespace eval punk {
} }
return [list_as_lines $displaylist] return [list_as_lines $displaylist]
}
proc dirfiles {{glob ""}} {
set contents [dirfiles_dict $glob]
return [dirfiles_dict_as_lines $contents]
} }
#experimental... leading colon makes it hard (impossible?) to call directly #experimental... leading colon makes it hard (impossible?) to call directly
@ -4220,9 +4224,14 @@ namespace eval punk {
if {![llength $args]} { if {![llength $args]} {
#ls is too slow even over a fairly low-latency network #ls is too slow even over a fairly low-latency network
#set out [runout -n ls -aFC] #set out [runout -n ls -aFC]
set result [pwd] set matchinfo [punk::dirfiles_dict]
set dircount [llength [dict get $matchinfo dirs]]
set filecount [llength [dict get $matchinfo files]]
set location [file normalize [dict get $matchinfo location]]
#result for glob is count of matches - use dirfiles etc for script access to results
set result [list location $location dircount $dircount filecount $filecount]
if {$::repl::running} { if {$::repl::running} {
set out [punk::dirfiles] set out [punk::dirfiles_dict_as_lines $matchinfo]
#puts stdout $out #puts stdout $out
#puts stderr [a+ white]$out[a+] #puts stderr [a+ white]$out[a+]
@ -4231,7 +4240,7 @@ namespace eval punk {
lappend chunklist [list result $result] lappend chunklist [list result $result]
set ::punk::last_run_display $chunklist set ::punk::last_run_display $chunklist
repl::term::set_console_title [file normalize $result] repl::term::set_console_title $location
} }
return $result return $result
} else { } else {
@ -4265,6 +4274,27 @@ namespace eval punk {
set path $curdir/$a1 set path $curdir/$a1
} }
if {![llength $atail] && ([string first "*" [file tail $path]] >= 0) || ([string first "?" [file tail $path]] >= 0)} {
#no more segments and we have a globchar at the end
set matchinfo [punk::dirfiles_dict [file tail $path]]
set dircount [llength [dict get $matchinfo dirs]]
set filecount [llength [dict get $matchinfo files]]
set location [file normalize [dict get $matchinfo location]]
#result for glob is count of matches - use dirfiles etc for script access to results
set result [list location $location dircount $dircount filecount $filecount]
if {$::repl::running} {
set out [punk::dirfiles_dict_as_lines $matchinfo]
set chunklist [list]
lappend chunklist [list stdout "[a+ white light]$out[a+]\n"]
lappend chunklist [list result $result]
set ::punk::last_run_display $chunklist
repl::term::set_console_title $location
}
return $result
}
if {[file type $path] eq "file"} { if {[file type $path] eq "file"} {
if {[string tolower [file extension $path]] in [list ".tcl" ".tm"]} { if {[string tolower [file extension $path]] in [list ".tcl" ".tm"]} {
set newargs $atail set newargs $atail
@ -4292,15 +4322,20 @@ namespace eval punk {
set path ../[file join {*}$args] set path ../[file join {*}$args]
} }
cd $path cd $path
#set out [runout -n ls -aFC] set matchinfo [punk::dirfiles_dict]
set out [punk::dirfiles] set dircount [llength [dict get $matchinfo dirs]]
set result [pwd] set filecount [llength [dict get $matchinfo files]]
#return $out\n[pwd] set location [file normalize [dict get $matchinfo location]]
set chunklist [list] #result for glob is count of matches - use dirfiles etc for script access to results
lappend chunklist [list stdout "[a+ white light]$out[a+]\n"] set result [list location $location dircount $dircount filecount $filecount]
lappend chunklist [list result $result]
set ::punk::last_run_display $chunklist
if {$::repl::running} { if {$::repl::running} {
set out [punk::dirfiles_dict_as_lines $matchinfo]
#return $out\n[pwd]
set chunklist [list]
lappend chunklist [list stdout "[a+ white light]$out[a+]\n"]
lappend chunklist [list result $result]
set ::punk::last_run_display $chunklist
repl::term::set_console_title $result repl::term::set_console_title $result
} }
return $result return $result

Loading…
Cancel
Save