Fix reverse sorts to keep folders first

This commit is contained in:
prpr 2023-06-13 10:53:47 +01:00
parent 2ea56fd045
commit 9b5c9553f0

View File

@ -303,7 +303,7 @@ if {$parent ne ""} {
" "
} }
proc s_file_stat {a b attr} { proc s_file_stat {a b attr {rev 0}} {
global dir global dir
set a "$dir/$a" set a "$dir/$a"
@ -325,8 +325,8 @@ proc s_file_stat {a b attr} {
if {[catch {file stat $b l}]} { return 0} if {[catch {file stat $b l}]} { return 0}
set bt $l($attr) set bt $l($attr)
if {$at < $bt} { return -1 } if {$at < $bt} { return [expr {$rev ? 1 : -1}] }
if {$at > $bt} { return 1 } if {$at > $bt} { return [expr {$rev ? -1 : 1}] }
return 0 return 0
} }
@ -334,10 +334,18 @@ proc s_time {a b} {
tailcall s_file_stat $a $b mtime tailcall s_file_stat $a $b mtime
} }
proc s_time_r {a b} {
tailcall s_file_stat $a $b mtime 1
}
proc s_size {a b} { proc s_size {a b} {
tailcall s_file_stat $a $b size tailcall s_file_stat $a $b size
} }
proc s_size_r {a b} {
tailcall s_file_stat $a $b size 1
}
proc s_ext {a b} { proc s_ext {a b} {
set at [file extension $a] set at [file extension $a]
set bt [file extension $b] set bt [file extension $b]
@ -350,11 +358,11 @@ proc s_ext {a b} {
set files [readdir -nocomplain $dir] set files [readdir -nocomplain $dir]
switch $order { switch $order {
5 { set files [lsort -command s_ext $files] }
1 { set files [lsort -command s_time $files] } 1 { set files [lsort -command s_time $files] }
2 { set files [lreverse [lsort -command s_time $files]] } 2 { set files [lsort -command s_time_r $files] }
3 { set files [lsort -command s_size $files] } 3 { set files [lsort -command s_size $files] }
4 { set files [lreverse [lsort -command s_size $files]] } 4 { set files [lsort -command s_size_r $files] }
5 { set files [lsort -command s_ext $files] }
default { set files [lsort -nocase $files] } default { set files [lsort -nocase $files] }
} }