Support optional fields for statfmt option (#1337)
* Support optional fields for `statfmt` option * Add documentation * Use special bytes for safety
This commit is contained in:
1 parent
443838e06f
commit
23418adc00
7 files changed
+33
-30
No files matched your search
@@ -167,7 +167,7 @@ The following options can be used to customize the behavior of lf:
|
||||
smartcase bool (default true)
|
||||
smartdia bool (default false)
|
||||
sortby string (default 'natural')
|
||||
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")
|
||||
tabstop int (default 8)
|
||||
tagfmt string (default "\033[31m")
|
||||
tempmarks string (default '')
|
||||
@@ -925,11 +925,11 @@ This option has no effect when 'ignoredia' is disabled.
|
||||
Sort type for directories.
|
||||
Currently supported sort types are 'natural', 'name', 'size', 'time', 'ctime', 'atime', and 'ext'.
|
||||
|
||||
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")
|
||||
|
||||
Format string of the file info shown in the bottom left corner.
|
||||
Special expansions are provided, '%p' as the file permissions, '%c' as the link count, '%u' as the user, '%g' as the group, '%s' as the file size, '%t' as the last modified time, and '%l' as the link target if it exists (otherwise a blank string). '%L' is the same as '%l' but with an arrow '-> ' prepended.
|
||||
On Windows, the link count, user and group fields are not supported and will be replaced with a blank string if specified. The default for Windows is "\033[36m%p\033[0m %s %t %L".
|
||||
Special expansions are provided, '%p' as the file permissions, '%c' as the link count, '%u' as the user, '%g' as the group, '%s' as the file size, '%t' as the last modified time, and '%l' as the link target.
|
||||
The `|` character splits the format string into sections. Any section containing a failed expansion (result is a blank string) is discarded and not shown.
|
||||
|
||||
tabstop int (default 8)
|
||||
|
||||
|
||||
+5
-7
@@ -170,7 +170,7 @@ The following options can be used to customize the behavior of lf:
|
||||
smartcase bool (default true)
|
||||
smartdia bool (default false)
|
||||
sortby string (default 'natural')
|
||||
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")
|
||||
tabstop int (default 8)
|
||||
tagfmt string (default "\033[31m")
|
||||
tempmarks string (default '')
|
||||
@@ -993,16 +993,14 @@ diacritic. This option has no effect when 'ignoredia' is disabled.
|
||||
Sort type for directories. Currently supported sort types are 'natural', 'name',
|
||||
'size', 'time', 'ctime', 'atime', and 'ext'.
|
||||
|
||||
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")
|
||||
|
||||
Format string of the file info shown in the bottom left corner. Special
|
||||
expansions are provided, '%p' as the file permissions, '%c' as the link count,
|
||||
'%u' as the user, '%g' as the group, '%s' as the file size, '%t' as the last
|
||||
modified time, and '%l' as the link target if it exists (otherwise a blank
|
||||
string). '%L' is the same as '%l' but with an arrow '-> ' prepended. On Windows,
|
||||
the link count, user and group fields are not supported and will be replaced
|
||||
with a blank string if specified. The default for Windows is "\033[36m%p\033[0m
|
||||
%s %t %L".
|
||||
modified time, and '%l' as the link target. The '|' character splits the format
|
||||
string into sections. Any section containing a failed expansion (result is a
|
||||
blank string) is discarded and not shown.
|
||||
|
||||
tabstop int (default 8)
|
||||
|
||||
|
||||
@@ -186,7 +186,7 @@ The following options can be used to customize the behavior of lf:
|
||||
smartcase bool (default true)
|
||||
smartdia bool (default false)
|
||||
sortby string (default 'natural')
|
||||
statfmt string (default "\e033[36m%p\e033[0m %c %u %g %s %t %L")
|
||||
statfmt string (default "\e033[36m%p\e033[0m| %c| %u| %g| %s| %t| -> %l")
|
||||
tabstop int (default 8)
|
||||
tagfmt string (default "\e033[31m")
|
||||
tempmarks string (default '')
|
||||
@@ -1102,10 +1102,10 @@ Override 'ignoredia' option when the pattern contains a character with diacritic
|
||||
Sort type for directories. Currently supported sort types are 'natural', 'name', 'size', 'time', 'ctime', 'atime', and 'ext'.
|
||||
.PP
|
||||
.EX
|
||||
statfmt string (default "\e033[36m%p\e033[0m %c %u %g %s %t %L")
|
||||
statfmt string (default "\e033[36m%p\e033[0m| %c| %u| %g| %s| %t| -> %l")
|
||||
.EE
|
||||
.PP
|
||||
Format string of the file info shown in the bottom left corner. Special expansions are provided, '%p' as the file permissions, '%c' as the link count, '%u' as the user, '%g' as the group, '%s' as the file size, '%t' as the last modified time, and '%l' as the link target if it exists (otherwise a blank string). '%L' is the same as '%l' but with an arrow '-> ' prepended. On Windows, the link count, user and group fields are not supported and will be replaced with a blank string if specified. The default for Windows is "\e033[36m%p\e033[0m %s %t %L".
|
||||
Format string of the file info shown in the bottom left corner. Special expansions are provided, '%p' as the file permissions, '%c' as the link count, '%u' as the user, '%g' as the group, '%s' as the file size, '%t' as the last modified time, and '%l' as the link target. The `|` character splits the format string into sections. Any section containing a failed expansion (result is a blank string) is discarded and not shown.
|
||||
.PP
|
||||
.EX
|
||||
tabstop int (default 8)
|
||||
|
||||
@@ -132,6 +132,7 @@ func init() {
|
||||
gOpts.selmode = "all"
|
||||
gOpts.shell = gDefaultShell
|
||||
gOpts.shellflag = gDefaultShellFlag
|
||||
gOpts.statfmt = "\033[36m%p\033[0m| %c| %u| %g| %s| %t| -> %l"
|
||||
gOpts.timefmt = time.ANSIC
|
||||
gOpts.infotimefmtnew = "Jan _2 15:04"
|
||||
gOpts.infotimefmtold = "Jan _2 2006"
|
||||
|
||||
@@ -170,8 +170,6 @@ func setDefaults() {
|
||||
|
||||
gOpts.cmds["doc"] = &execExpr{"$", `"$lf" -doc | $PAGER`}
|
||||
gOpts.keys["<f-1>"] = &callExpr{"doc", nil, 1}
|
||||
|
||||
gOpts.statfmt = "\033[36m%p\033[0m %c %u %g %s %t %L"
|
||||
}
|
||||
|
||||
func setUserUmask() {
|
||||
|
||||
@@ -136,8 +136,6 @@ func setDefaults() {
|
||||
|
||||
gOpts.cmds["doc"] = &execExpr{"!", "%lf% -doc | %PAGER%"}
|
||||
gOpts.keys["<f-1>"] = &callExpr{"doc", nil, 1}
|
||||
|
||||
gOpts.statfmt = "\033[36m%p\033[0m %s %t %L"
|
||||
}
|
||||
|
||||
func setUserUmask() {}
|
||||
|
||||
@@ -721,20 +721,28 @@ func (ui *ui) loadFileInfo(nav *nav) {
|
||||
return
|
||||
}
|
||||
|
||||
linkTargetArrow := ""
|
||||
if curr.linkTarget != "" {
|
||||
linkTargetArrow = "-> " + curr.linkTarget
|
||||
statfmt := strings.ReplaceAll(gOpts.statfmt, "|", "\x1f")
|
||||
replace := func(s string, val string) {
|
||||
if val == "" {
|
||||
val = "\x00"
|
||||
}
|
||||
statfmt = strings.ReplaceAll(statfmt, s, val)
|
||||
}
|
||||
replace("%p", curr.Mode().String())
|
||||
replace("%c", linkCount(curr))
|
||||
replace("%u", userName(curr))
|
||||
replace("%g", groupName(curr))
|
||||
replace("%s", humanize(curr.Size()))
|
||||
replace("%t", curr.ModTime().Format(gOpts.timefmt))
|
||||
replace("%l", curr.linkTarget)
|
||||
|
||||
fileInfo := ""
|
||||
for _, section := range strings.Split(statfmt, "\x1f") {
|
||||
if !strings.Contains(section, "\x00") {
|
||||
fileInfo += section
|
||||
}
|
||||
}
|
||||
|
||||
fileInfo := gOpts.statfmt
|
||||
fileInfo = strings.Replace(fileInfo, "%p", curr.Mode().String(), -1)
|
||||
fileInfo = strings.Replace(fileInfo, "%c", linkCount(curr), -1)
|
||||
fileInfo = strings.Replace(fileInfo, "%u", userName(curr), -1)
|
||||
fileInfo = strings.Replace(fileInfo, "%g", groupName(curr), -1)
|
||||
fileInfo = strings.Replace(fileInfo, "%s", humanize(curr.Size()), -1)
|
||||
fileInfo = strings.Replace(fileInfo, "%t", curr.ModTime().Format(gOpts.timefmt), -1)
|
||||
fileInfo = strings.Replace(fileInfo, "%l", curr.linkTarget, -1)
|
||||
fileInfo = strings.Replace(fileInfo, "%L", linkTargetArrow, -1)
|
||||
ui.echo(fileInfo)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user