8000 Support optional fields for `statfmt` option by joelim-work · Pull Request #1337 · gokcehan/lf · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Support optional fields for statfmt option #1337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 '')
Expand Down Expand Up @@ -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)

Expand Down
12 changes: 5 additions & 7 deletions docstring.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions lf.1
Original file line number Diff line number Diff line change
Expand Up @@ -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 '')
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 0 additions & 2 deletions os.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 0 additions & 2 deletions os_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Expand Down
36 changes: 22 additions & 14 deletions ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -721,20 +721,28 @@ func (ui *ui) loadFileInfo(nav *nav) {
return
}

linkTargetArrow := ""
if curr.linkTarget != "" {
linkTargetArrow = "-> " + curr.linkTarget
}

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)
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
}
}

ui.echo(fileInfo)
}

Expand Down
0