Support btime in sortby and info (#2042)

* Add support for `btime` in `sortby` and `info`

* Update documentation

* Minor design improvements
This commit is contained in:
CatsDeservePets authored and GitHub committed 2025-07-19 13:06:34 +10:00
1 parent 4758ef621c
commit 87c994b9de
7 files changed
+85 -21

No files matched your search

+15 -2
View File
@@ -296,6 +296,7 @@ The following additional keybindings are provided by default:
map ss :set sortby size; set info size map ss :set sortby size; set info size
map st :set sortby time; set info time map st :set sortby time; set info time
map sa :set sortby atime; set info atime map sa :set sortby atime; set info atime
map sb :set sortby btime; set info btime
map sc :set sortby ctime; set info ctime map sc :set sortby ctime; set info ctime
map se :set sortby ext; set info map se :set sortby ext; set info
map gh cd ~ map gh cd ~
@@ -853,7 +854,7 @@ Apply filter pattern after each keystroke during filtering.
## info ([]string) (default ``) ## info ([]string) (default ``)
A list of information that is shown for directory items at the right side of the pane. A list of information that is shown for directory items at the right side of the pane.
Currently supported information types are `size`, `time`, `atime`, `ctime`, `perm`, `user`, `group` and `custom`. Currently supported information types are `size`, `time`, `atime`, `btime`, `ctime`, `perm`, `user`, `group` and `custom`.
The `custom` type is empty by default and can be updated using the `addcustominfo` command. The `custom` type is empty by default and can be updated using the `addcustominfo` command.
Information is only shown when the pane width is more than twice the width of information. Information is only shown when the pane width is more than twice the width of information.
@@ -998,7 +999,19 @@ This option has no effect when `ignoredia` is disabled.
## sortby (string) (default `natural`) ## sortby (string) (default `natural`)
Sort type for directories. Sort type for directories.
Currently supported sort types are `natural`, `name`, `size`, `time`, `ctime`, `atime`, `ext` and `custom`. Currently supported sort types are `natural`, `name`, `size`, `time`, `atime`, `btime`, `ctime`, `ext` and `custom`.
Meaning of each sort type:
natural file name (track_2.flac comes before track_10.flac)
name file name (track_10.flac comes before track_2.flac)
size file size
time time of last data modification
atime time of last access
btime time of file birth
ctime time of last status (inode) change
ext file extension
custom property defined via `addcustominfo`
## statfmt (string) (default `\033[36m%p\033[0m| %c| %u| %g| %S| %t| -> %l`) ## statfmt (string) (default `\033[36m%p\033[0m| %c| %u| %g| %S| %t| -> %l`)
+18 -5
View File
@@ -287,6 +287,7 @@ The following additional keybindings are provided by default:
map ss :set sortby size; set info size map ss :set sortby size; set info size
map st :set sortby time; set info time map st :set sortby time; set info time
map sa :set sortby atime; set info atime map sa :set sortby atime; set info atime
map sb :set sortby btime; set info btime
map sc :set sortby ctime; set info ctime map sc :set sortby ctime; set info ctime
map se :set sortby ext; set info map se :set sortby ext; set info
map gh cd ~ map gh cd ~
@@ -908,10 +909,10 @@ info ([]string) (default ``)
A list of information that is shown for directory items at the right A list of information that is shown for directory items at the right
side of the pane. Currently supported information types are size, time, side of the pane. Currently supported information types are size, time,
atime, ctime, perm, user, group and custom. The custom type is empty by atime, btime, ctime, perm, user, group and custom. The custom type is
default and can be updated using the addcustominfo command. Information empty by default and can be updated using the addcustominfo command.
is only shown when the pane width is more than twice the width of Information is only shown when the pane width is more than twice the
information. width of information.
infotimefmtnew (string) (default Jan _2 15:04) infotimefmtnew (string) (default Jan _2 15:04)
@@ -1086,7 +1087,19 @@ diacritic. This option has no effect when ignoredia is disabled.
sortby (string) (default natural) sortby (string) (default natural)
Sort type for directories. Currently supported sort types are natural, Sort type for directories. Currently supported sort types are natural,
name, size, time, ctime, atime, ext and custom. name, size, time, atime, btime, ctime, ext and custom.
Meaning of each sort type:
natural file name (track_2.flac comes before track_10.flac)
name file name (track_10.flac comes before track_2.flac)
size file size
time time of last data modification
atime time of last access
btime time of file birth
ctime time of last status (inode) change
ext file extension
custom property defined via `addcustominfo`
statfmt (string) (default \033[36m%p\033[0m| %c| %u| %g| %S| %t| -> %l) statfmt (string) (default \033[36m%p\033[0m| %c| %u| %g| %S| %t| -> %l)
+4 -4
View File
@@ -268,9 +268,9 @@ func (e *setExpr) eval(app *app, args []string) {
toks := strings.Split(e.val, ":") toks := strings.Split(e.val, ":")
for _, s := range toks { for _, s := range toks {
switch s { switch s {
case "size", "time", "atime", "ctime", "perm", "user", "group", "custom": case "size", "time", "atime", "btime", "ctime", "perm", "user", "group", "custom":
default: default:
app.ui.echoerr("info: should consist of 'size', 'time', 'atime', 'ctime', 'perm', 'user', 'group' or 'custom' separated with colon") app.ui.echoerr("info: should consist of 'size', 'time', 'atime', 'btime', 'ctime', 'perm', 'user', 'group' or 'custom' separated with colon")
return return
} }
} }
@@ -504,9 +504,9 @@ func (e *setLocalExpr) eval(app *app, args []string) {
toks := strings.Split(e.val, ":") toks := strings.Split(e.val, ":")
for _, s := range toks { for _, s := range toks {
switch s { switch s {
case "size", "time", "atime", "ctime", "perm", "user", "group", "custom": case "size", "time", "atime", "btime", "ctime", "perm", "user", "group", "custom":
default: default:
app.ui.echoerr("info: should consist of 'size', 'time', 'atime', 'ctime', 'perm', 'user', 'group' or 'custom' separated with colon") app.ui.echoerr("info: should consist of 'size', 'time', 'atime', 'btime', 'ctime', 'perm', 'user', 'group' or 'custom' separated with colon")
return return
} }
} }
+20 -4
View File
@@ -310,6 +310,7 @@ map sn :set sortby natural; set info
map ss :set sortby size; set info size map ss :set sortby size; set info size
map st :set sortby time; set info time map st :set sortby time; set info time
map sa :set sortby atime; set info atime map sa :set sortby atime; set info atime
map sb :set sortby btime; set info btime
map sc :set sortby ctime; set info ctime map sc :set sortby ctime; set info ctime
map se :set sortby ext; set info map se :set sortby ext; set info
map gh cd \(ti map gh cd \(ti
@@ -792,8 +793,9 @@ Apply filter pattern after each keystroke during filtering.
A list of information that is shown for directory items at the right A list of information that is shown for directory items at the right
side of the pane. side of the pane.
Currently supported information types are \f[CR]size\f[R], Currently supported information types are \f[CR]size\f[R],
\f[CR]time\f[R], \f[CR]atime\f[R], \f[CR]ctime\f[R], \f[CR]perm\f[R], \f[CR]time\f[R], \f[CR]atime\f[R], \f[CR]btime\f[R], \f[CR]ctime\f[R],
\f[CR]user\f[R], \f[CR]group\f[R] and \f[CR]custom\f[R]. \f[CR]perm\f[R], \f[CR]user\f[R], \f[CR]group\f[R] and
\f[CR]custom\f[R].
The \f[CR]custom\f[R] type is empty by default and can be updated using The \f[CR]custom\f[R] type is empty by default and can be updated using
the \f[CR]addcustominfo\f[R] command. the \f[CR]addcustominfo\f[R] command.
Information is only shown when the pane width is more than twice the Information is only shown when the pane width is more than twice the
@@ -944,8 +946,22 @@ This option has no effect when \f[CR]ignoredia\f[R] is disabled.
.SS sortby (string) (default \f[CR]natural\f[R]) .SS sortby (string) (default \f[CR]natural\f[R])
Sort type for directories. Sort type for directories.
Currently supported sort types are \f[CR]natural\f[R], \f[CR]name\f[R], Currently supported sort types are \f[CR]natural\f[R], \f[CR]name\f[R],
\f[CR]size\f[R], \f[CR]time\f[R], \f[CR]ctime\f[R], \f[CR]atime\f[R], \f[CR]size\f[R], \f[CR]time\f[R], \f[CR]atime\f[R], \f[CR]btime\f[R],
\f[CR]ext\f[R] and \f[CR]custom\f[R]. \f[CR]ctime\f[R], \f[CR]ext\f[R] and \f[CR]custom\f[R].
.PP
Meaning of each sort type:
.IP
.EX
natural file name (track_2.flac comes before track_10.flac)
name file name (track_10.flac comes before track_2.flac)
size file size
time time of last data modification
atime time of last access
btime time of file birth
ctime time of last status (inode) change
ext file extension
custom property defined via \(gaaddcustominfo\(ga
.EE
.SS statfmt (string) (default \f[CR]\(rs033[36m%p\(rs033[0m| %c| %u| %g| %S| %t| \-> %l\f[R]) .SS statfmt (string) (default \f[CR]\(rs033[36m%p\(rs033[0m| %c| %u| %g| %S| %t| \-> %l\f[R])
Format string of the file info shown in the bottom left corner. Format string of the file info shown in the bottom left corner.
Special expansions are provided, \f[CR]%p\f[R] as the file permissions, Special expansions are provided, \f[CR]%p\f[R] as the file permissions,
+22 -5
View File
@@ -36,6 +36,7 @@ type file struct {
dirCount int dirCount int
dirSize int64 dirSize int64
accessTime time.Time accessTime time.Time
birthTime time.Time
changeTime time.Time changeTime time.Time
customInfo string customInfo string
ext string ext string
@@ -54,6 +55,7 @@ func newFile(path string) *file {
dirCount: -1, dirCount: -1,
dirSize: -1, dirSize: -1,
accessTime: time.Unix(0, 0), accessTime: time.Unix(0, 0),
birthTime: time.Unix(0, 0),
changeTime: time.Unix(0, 0), changeTime: time.Unix(0, 0),
customInfo: "", customInfo: "",
ext: "", ext: "",
@@ -80,13 +82,19 @@ func newFile(path string) *file {
ts := times.Get(lstat) ts := times.Get(lstat)
at := ts.AccessTime() at := ts.AccessTime()
var ct time.Time // from times docs:
// from times docs: ChangeTime() panics unless HasChangeTime() is true // ChangeTime() panics unless HasChangeTime() is true and
// BirthTime() panics unless HasBirthTime() is true.
// default to ModTime if BirthTime cannot be determined
bt := lstat.ModTime()
if ts.HasBirthTime() {
bt = ts.BirthTime()
}
// default to ModTime if ChangeTime cannot be determined
ct := lstat.ModTime()
if ts.HasChangeTime() { if ts.HasChangeTime() {
ct = ts.ChangeTime() ct = ts.ChangeTime()
} else {
// fall back to ModTime if ChangeTime cannot be determined
ct = lstat.ModTime()
} }
dirCount := -1 dirCount := -1
@@ -114,6 +122,7 @@ func newFile(path string) *file {
dirCount: dirCount, dirCount: dirCount,
dirSize: -1, dirSize: -1,
accessTime: at, accessTime: at,
birthTime: bt,
changeTime: ct, changeTime: ct,
customInfo: "", customInfo: "",
ext: getFileExtension(lstat), ext: getFileExtension(lstat),
@@ -322,6 +331,14 @@ func (dir *dir) sort() {
return dir.files[j].accessTime.Before(dir.files[i].accessTime) return dir.files[j].accessTime.Before(dir.files[i].accessTime)
} }
}) })
case btimeSort:
sort.SliceStable(dir.files, func(i, j int) bool {
if !dir.reverse {
return dir.files[i].birthTime.Before(dir.files[j].birthTime)
} else {
return dir.files[j].birthTime.Before(dir.files[i].birthTime)
}
})
case ctimeSort: case ctimeSort:
sort.SliceStable(dir.files, func(i, j int) bool { sort.SliceStable(dir.files, func(i, j int) bool {
if !dir.reverse { if !dir.reverse {
+4 -1
View File
@@ -15,6 +15,7 @@ const (
sizeSort sortMethod = "size" sizeSort sortMethod = "size"
timeSort sortMethod = "time" timeSort sortMethod = "time"
atimeSort sortMethod = "atime" atimeSort sortMethod = "atime"
btimeSort sortMethod = "btime"
ctimeSort sortMethod = "ctime" ctimeSort sortMethod = "ctime"
extSort sortMethod = "ext" extSort sortMethod = "ext"
customSort sortMethod = "custom" customSort sortMethod = "custom"
@@ -26,12 +27,13 @@ func isValidSortMethod(method sortMethod) bool {
method == sizeSort || method == sizeSort ||
method == timeSort || method == timeSort ||
method == atimeSort || method == atimeSort ||
method == btimeSort ||
method == ctimeSort || method == ctimeSort ||
method == extSort || method == extSort ||
method == customSort method == customSort
} }
const invalidSortErrorMessage = `sortby: value should either be 'natural', 'name', 'size', 'time', 'atime', 'ctime', 'ext' or 'custom'` const invalidSortErrorMessage = `sortby: value should either be 'natural', 'name', 'size', 'time', 'atime', 'btime', 'ctime', 'ext' or 'custom'`
var gOpts struct { var gOpts struct {
anchorfind bool anchorfind bool
@@ -344,6 +346,7 @@ func init() {
"ss": &listExpr{[]expr{&setExpr{"sortby", "size"}, &setExpr{"info", "size"}}, 1}, "ss": &listExpr{[]expr{&setExpr{"sortby", "size"}, &setExpr{"info", "size"}}, 1},
"st": &listExpr{[]expr{&setExpr{"sortby", "time"}, &setExpr{"info", "time"}}, 1}, "st": &listExpr{[]expr{&setExpr{"sortby", "time"}, &setExpr{"info", "time"}}, 1},
"sa": &listExpr{[]expr{&setExpr{"sortby", "atime"}, &setExpr{"info", "atime"}}, 1}, "sa": &listExpr{[]expr{&setExpr{"sortby", "atime"}, &setExpr{"info", "atime"}}, 1},
"sb": &listExpr{[]expr{&setExpr{"sortby", "btime"}, &setExpr{"info", "btime"}}, 1},
"sc": &listExpr{[]expr{&setExpr{"sortby", "ctime"}, &setExpr{"info", "ctime"}}, 1}, "sc": &listExpr{[]expr{&setExpr{"sortby", "ctime"}, &setExpr{"info", "ctime"}}, 1},
"se": &listExpr{[]expr{&setExpr{"sortby", "ext"}, &setExpr{"info", ""}}, 1}, "se": &listExpr{[]expr{&setExpr{"sortby", "ext"}, &setExpr{"info", ""}}, 1},
"gh": &callExpr{"cd", []string{"~"}, 1}, "gh": &callExpr{"cd", []string{"~"}, 1},
+2
View File
@@ -323,6 +323,8 @@ func fileInfo(f *file, d *dir, userWidth int, groupWidth int, customWidth int) (
fmt.Fprintf(&info, " %*s", max(len(gOpts.infotimefmtnew), len(gOpts.infotimefmtold)), infotimefmt(f.ModTime())) fmt.Fprintf(&info, " %*s", max(len(gOpts.infotimefmtnew), len(gOpts.infotimefmtold)), infotimefmt(f.ModTime()))
case "atime": case "atime":
fmt.Fprintf(&info, " %*s", max(len(gOpts.infotimefmtnew), len(gOpts.infotimefmtold)), infotimefmt(f.accessTime)) fmt.Fprintf(&info, " %*s", max(len(gOpts.infotimefmtnew), len(gOpts.infotimefmtold)), infotimefmt(f.accessTime))
case "btime":
fmt.Fprintf(&info, " %*s", max(len(gOpts.infotimefmtnew), len(gOpts.infotimefmtold)), infotimefmt(f.birthTime))
case "ctime": case "ctime":
fmt.Fprintf(&info, " %*s", max(len(gOpts.infotimefmtnew), len(gOpts.infotimefmtold)), infotimefmt(f.changeTime)) fmt.Fprintf(&info, " %*s", max(len(gOpts.infotimefmtnew), len(gOpts.infotimefmtold)), infotimefmt(f.changeTime))
case "perm": case "perm":