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:
1 parent
4758ef621c
commit
87c994b9de
7 files changed
+85
-21
No files matched your search
@@ -296,6 +296,7 @@ The following additional keybindings are provided by default:
|
||||
map ss :set sortby size; set info size
|
||||
map st :set sortby time; set info time
|
||||
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 se :set sortby ext; set info
|
||||
map gh cd ~
|
||||
@@ -853,7 +854,7 @@ Apply filter pattern after each keystroke during filtering.
|
||||
## info ([]string) (default ``)
|
||||
|
||||
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.
|
||||
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`)
|
||||
|
||||
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`)
|
||||
|
||||
|
||||
@@ -287,6 +287,7 @@ The following additional keybindings are provided by default:
|
||||
map ss :set sortby size; set info size
|
||||
map st :set sortby time; set info time
|
||||
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 se :set sortby ext; set info
|
||||
map gh cd ~
|
||||
@@ -908,10 +909,10 @@ info ([]string) (default ``)
|
||||
|
||||
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. 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.
|
||||
atime, btime, ctime, perm, user, group and custom. 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.
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
|
||||
@@ -268,9 +268,9 @@ func (e *setExpr) eval(app *app, args []string) {
|
||||
toks := strings.Split(e.val, ":")
|
||||
for _, s := range toks {
|
||||
switch s {
|
||||
case "size", "time", "atime", "ctime", "perm", "user", "group", "custom":
|
||||
case "size", "time", "atime", "btime", "ctime", "perm", "user", "group", "custom":
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -504,9 +504,9 @@ func (e *setLocalExpr) eval(app *app, args []string) {
|
||||
toks := strings.Split(e.val, ":")
|
||||
for _, s := range toks {
|
||||
switch s {
|
||||
case "size", "time", "atime", "ctime", "perm", "user", "group", "custom":
|
||||
case "size", "time", "atime", "btime", "ctime", "perm", "user", "group", "custom":
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -310,6 +310,7 @@ map sn :set sortby natural; set info
|
||||
map ss :set sortby size; set info size
|
||||
map st :set sortby time; set info time
|
||||
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 se :set sortby ext; set info
|
||||
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
|
||||
side of the pane.
|
||||
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]user\f[R], \f[CR]group\f[R] and \f[CR]custom\f[R].
|
||||
\f[CR]time\f[R], \f[CR]atime\f[R], \f[CR]btime\f[R], \f[CR]ctime\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]addcustominfo\f[R] command.
|
||||
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])
|
||||
Sort type for directories.
|
||||
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]ext\f[R] and \f[CR]custom\f[R].
|
||||
\f[CR]size\f[R], \f[CR]time\f[R], \f[CR]atime\f[R], \f[CR]btime\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])
|
||||
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,
|
||||
|
||||
@@ -36,6 +36,7 @@ type file struct {
|
||||
dirCount int
|
||||
dirSize int64
|
||||
accessTime time.Time
|
||||
birthTime time.Time
|
||||
changeTime time.Time
|
||||
customInfo string
|
||||
ext string
|
||||
@@ -54,6 +55,7 @@ func newFile(path string) *file {
|
||||
dirCount: -1,
|
||||
dirSize: -1,
|
||||
accessTime: time.Unix(0, 0),
|
||||
birthTime: time.Unix(0, 0),
|
||||
changeTime: time.Unix(0, 0),
|
||||
customInfo: "",
|
||||
ext: "",
|
||||
@@ -80,13 +82,19 @@ func newFile(path string) *file {
|
||||
|
||||
ts := times.Get(lstat)
|
||||
at := ts.AccessTime()
|
||||
var ct time.Time
|
||||
// from times docs: ChangeTime() panics unless HasChangeTime() is true
|
||||
// from times docs:
|
||||
// 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() {
|
||||
ct = ts.ChangeTime()
|
||||
} else {
|
||||
// fall back to ModTime if ChangeTime cannot be determined
|
||||
ct = lstat.ModTime()
|
||||
}
|
||||
|
||||
dirCount := -1
|
||||
@@ -114,6 +122,7 @@ func newFile(path string) *file {
|
||||
dirCount: dirCount,
|
||||
dirSize: -1,
|
||||
accessTime: at,
|
||||
birthTime: bt,
|
||||
changeTime: ct,
|
||||
customInfo: "",
|
||||
ext: getFileExtension(lstat),
|
||||
@@ -322,6 +331,14 @@ func (dir *dir) sort() {
|
||||
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:
|
||||
sort.SliceStable(dir.files, func(i, j int) bool {
|
||||
if !dir.reverse {
|
||||
|
||||
@@ -15,6 +15,7 @@ const (
|
||||
sizeSort sortMethod = "size"
|
||||
timeSort sortMethod = "time"
|
||||
atimeSort sortMethod = "atime"
|
||||
btimeSort sortMethod = "btime"
|
||||
ctimeSort sortMethod = "ctime"
|
||||
extSort sortMethod = "ext"
|
||||
customSort sortMethod = "custom"
|
||||
@@ -26,12 +27,13 @@ func isValidSortMethod(method sortMethod) bool {
|
||||
method == sizeSort ||
|
||||
method == timeSort ||
|
||||
method == atimeSort ||
|
||||
method == btimeSort ||
|
||||
method == ctimeSort ||
|
||||
method == extSort ||
|
||||
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 {
|
||||
anchorfind bool
|
||||
@@ -344,6 +346,7 @@ func init() {
|
||||
"ss": &listExpr{[]expr{&setExpr{"sortby", "size"}, &setExpr{"info", "size"}}, 1},
|
||||
"st": &listExpr{[]expr{&setExpr{"sortby", "time"}, &setExpr{"info", "time"}}, 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},
|
||||
"se": &listExpr{[]expr{&setExpr{"sortby", "ext"}, &setExpr{"info", ""}}, 1},
|
||||
"gh": &callExpr{"cd", []string{"~"}, 1},
|
||||
|
||||
@@ -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()))
|
||||
case "atime":
|
||||
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":
|
||||
fmt.Fprintf(&info, " %*s", max(len(gOpts.infotimefmtnew), len(gOpts.infotimefmtold)), infotimefmt(f.changeTime))
|
||||
case "perm":
|
||||
|
||||
Reference in new issue
Block a user