Add statfmt option (#1288)
* Add `fileinfofmt` option * echof is now unused * Use different default for Windows * Add new line to docs * Indent placeholders description in documentation * Change option name to `statfmt` * Use plain text format for documentation
This commit is contained in:
1 parent
59f32193ae
commit
2ab4b14e88
9 files changed
+50
-17
No files matched your search
@@ -211,6 +211,7 @@ var (
|
|||||||
"shellflag",
|
"shellflag",
|
||||||
"shellopts",
|
"shellopts",
|
||||||
"sortby",
|
"sortby",
|
||||||
|
"statfmt",
|
||||||
"timefmt",
|
"timefmt",
|
||||||
"tempmarks",
|
"tempmarks",
|
||||||
"tagfmt",
|
"tagfmt",
|
||||||
|
|||||||
@@ -166,6 +166,7 @@ The following options can be used to customize the behavior of lf:
|
|||||||
smartcase bool (default true)
|
smartcase bool (default true)
|
||||||
smartdia bool (default false)
|
smartdia bool (default false)
|
||||||
sortby string (default 'natural')
|
sortby string (default 'natural')
|
||||||
|
statfmt string (default "\033[36m%p\033[0m %c %u %g %s %t %L")
|
||||||
tabstop int (default 8)
|
tabstop int (default 8)
|
||||||
tagfmt string (default "\033[31m")
|
tagfmt string (default "\033[31m")
|
||||||
tempmarks string (default '')
|
tempmarks string (default '')
|
||||||
@@ -909,6 +910,12 @@ This option has no effect when 'ignoredia' is disabled.
|
|||||||
Sort type for directories.
|
Sort type for directories.
|
||||||
Currently supported sort types are 'natural', 'name', 'size', 'time', 'ctime', 'atime', and 'ext'.
|
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")
|
||||||
|
|
||||||
|
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".
|
||||||
|
|
||||||
tabstop int (default 8)
|
tabstop int (default 8)
|
||||||
|
|
||||||
Number of space characters to show for horizontal tabulation (U+0009) character.
|
Number of space characters to show for horizontal tabulation (U+0009) character.
|
||||||
|
|||||||
@@ -169,6 +169,7 @@ The following options can be used to customize the behavior of lf:
|
|||||||
smartcase bool (default true)
|
smartcase bool (default true)
|
||||||
smartdia bool (default false)
|
smartdia bool (default false)
|
||||||
sortby string (default 'natural')
|
sortby string (default 'natural')
|
||||||
|
statfmt string (default "\033[36m%p\033[0m %c %u %g %s %t %L")
|
||||||
tabstop int (default 8)
|
tabstop int (default 8)
|
||||||
tagfmt string (default "\033[31m")
|
tagfmt string (default "\033[31m")
|
||||||
tempmarks string (default '')
|
tempmarks string (default '')
|
||||||
@@ -974,6 +975,17 @@ diacritic. This option has no effect when 'ignoredia' is disabled.
|
|||||||
Sort type for directories. Currently supported sort types are 'natural', 'name',
|
Sort type for directories. Currently supported sort types are 'natural', 'name',
|
||||||
'size', 'time', 'ctime', 'atime', and 'ext'.
|
'size', 'time', 'ctime', 'atime', and 'ext'.
|
||||||
|
|
||||||
|
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".
|
||||||
|
|
||||||
tabstop int (default 8)
|
tabstop int (default 8)
|
||||||
|
|
||||||
Number of space characters to show for horizontal tabulation (U+0009) character.
|
Number of space characters to show for horizontal tabulation (U+0009) character.
|
||||||
|
|||||||
@@ -801,6 +801,8 @@ func (e *setExpr) eval(app *app, args []string) {
|
|||||||
}
|
}
|
||||||
app.nav.sort()
|
app.nav.sort()
|
||||||
app.ui.sort()
|
app.ui.sort()
|
||||||
|
case "statfmt":
|
||||||
|
gOpts.statfmt = e.val
|
||||||
case "tabstop":
|
case "tabstop":
|
||||||
n, err := strconv.Atoi(e.val)
|
n, err := strconv.Atoi(e.val)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -185,6 +185,7 @@ The following options can be used to customize the behavior of lf:
|
|||||||
smartcase bool (default true)
|
smartcase bool (default true)
|
||||||
smartdia bool (default false)
|
smartdia bool (default false)
|
||||||
sortby string (default 'natural')
|
sortby string (default 'natural')
|
||||||
|
statfmt string (default "\e033[36m%p\e033[0m %c %u %g %s %t %L")
|
||||||
tabstop int (default 8)
|
tabstop int (default 8)
|
||||||
tagfmt string (default "\e033[31m")
|
tagfmt string (default "\e033[31m")
|
||||||
tempmarks string (default '')
|
tempmarks string (default '')
|
||||||
@@ -1080,6 +1081,12 @@ Override 'ignoredia' option when the pattern contains a character with diacritic
|
|||||||
.PP
|
.PP
|
||||||
Sort type for directories. Currently supported sort types are 'natural', 'name', 'size', 'time', 'ctime', 'atime', and 'ext'.
|
Sort type for directories. Currently supported sort types are 'natural', 'name', 'size', 'time', 'ctime', 'atime', and 'ext'.
|
||||||
.PP
|
.PP
|
||||||
|
.EX
|
||||||
|
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".
|
||||||
|
.PP
|
||||||
.EX
|
.EX
|
||||||
tabstop int (default 8)
|
tabstop int (default 8)
|
||||||
.EE
|
.EE
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ var gOpts struct {
|
|||||||
selmode string
|
selmode string
|
||||||
shell string
|
shell string
|
||||||
shellflag string
|
shellflag string
|
||||||
|
statfmt string
|
||||||
timefmt string
|
timefmt string
|
||||||
infotimefmtnew string
|
infotimefmtnew string
|
||||||
infotimefmtold string
|
infotimefmtold string
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
"os/user"
|
"os/user"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
@@ -164,6 +165,8 @@ func setDefaults() {
|
|||||||
|
|
||||||
gOpts.cmds["doc"] = &execExpr{"$", `"$lf" -doc | $PAGER`}
|
gOpts.cmds["doc"] = &execExpr{"$", `"$lf" -doc | $PAGER`}
|
||||||
gOpts.keys["<f-1>"] = &callExpr{"doc", nil, 1}
|
gOpts.keys["<f-1>"] = &callExpr{"doc", nil, 1}
|
||||||
|
|
||||||
|
gOpts.statfmt = "\033[36m%p\033[0m %c %u %g %s %t %L"
|
||||||
}
|
}
|
||||||
|
|
||||||
func setUserUmask() {
|
func setUserUmask() {
|
||||||
@@ -190,7 +193,7 @@ func isHidden(f os.FileInfo, path string, hiddenfiles []string) bool {
|
|||||||
func userName(f os.FileInfo) string {
|
func userName(f os.FileInfo) string {
|
||||||
if stat, ok := f.Sys().(*syscall.Stat_t); ok {
|
if stat, ok := f.Sys().(*syscall.Stat_t); ok {
|
||||||
if u, err := user.LookupId(fmt.Sprint(stat.Uid)); err == nil {
|
if u, err := user.LookupId(fmt.Sprint(stat.Uid)); err == nil {
|
||||||
return fmt.Sprintf("%v ", u.Username)
|
return u.Username
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
@@ -199,7 +202,7 @@ func userName(f os.FileInfo) string {
|
|||||||
func groupName(f os.FileInfo) string {
|
func groupName(f os.FileInfo) string {
|
||||||
if stat, ok := f.Sys().(*syscall.Stat_t); ok {
|
if stat, ok := f.Sys().(*syscall.Stat_t); ok {
|
||||||
if g, err := user.LookupGroupId(fmt.Sprint(stat.Gid)); err == nil {
|
if g, err := user.LookupGroupId(fmt.Sprint(stat.Gid)); err == nil {
|
||||||
return fmt.Sprintf("%v ", g.Name)
|
return g.Name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
@@ -207,7 +210,7 @@ func groupName(f os.FileInfo) string {
|
|||||||
|
|
||||||
func linkCount(f os.FileInfo) string {
|
func linkCount(f os.FileInfo) string {
|
||||||
if stat, ok := f.Sys().(*syscall.Stat_t); ok {
|
if stat, ok := f.Sys().(*syscall.Stat_t); ok {
|
||||||
return fmt.Sprintf("%v ", stat.Nlink)
|
return strconv.FormatUint(stat.Nlink, 10)
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,6 +123,8 @@ func setDefaults() {
|
|||||||
|
|
||||||
gOpts.cmds["doc"] = &execExpr{"!", "%lf% -doc | %PAGER%"}
|
gOpts.cmds["doc"] = &execExpr{"!", "%lf% -doc | %PAGER%"}
|
||||||
gOpts.keys["<f-1>"] = &callExpr{"doc", nil, 1}
|
gOpts.keys["<f-1>"] = &callExpr{"doc", nil, 1}
|
||||||
|
|
||||||
|
gOpts.statfmt = "\033[36m%p\033[0m %s %t %L"
|
||||||
}
|
}
|
||||||
|
|
||||||
func setUserUmask() {}
|
func setUserUmask() {}
|
||||||
|
|||||||
@@ -648,10 +648,6 @@ func (ui *ui) echo(msg string) {
|
|||||||
ui.msg = msg
|
ui.msg = msg
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ui *ui) echof(format string, a ...interface{}) {
|
|
||||||
ui.echo(fmt.Sprintf(format, a...))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ui *ui) echomsg(msg string) {
|
func (ui *ui) echomsg(msg string) {
|
||||||
ui.msg = msg
|
ui.msg = msg
|
||||||
log.Print(msg)
|
log.Print(msg)
|
||||||
@@ -722,19 +718,21 @@ func (ui *ui) loadFileInfo(nav *nav) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var linkTarget string
|
linkTargetArrow := ""
|
||||||
if curr.linkTarget != "" {
|
if curr.linkTarget != "" {
|
||||||
linkTarget = " -> " + curr.linkTarget
|
linkTargetArrow = "-> " + curr.linkTarget
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.echof("%v %v%v%v%4s %v%s",
|
fileInfo := gOpts.statfmt
|
||||||
curr.Mode(),
|
fileInfo = strings.Replace(fileInfo, "%p", curr.Mode().String(), -1)
|
||||||
linkCount(curr), // optional
|
fileInfo = strings.Replace(fileInfo, "%c", linkCount(curr), -1)
|
||||||
userName(curr), // optional
|
fileInfo = strings.Replace(fileInfo, "%u", userName(curr), -1)
|
||||||
groupName(curr), // optional
|
fileInfo = strings.Replace(fileInfo, "%g", groupName(curr), -1)
|
||||||
humanize(curr.Size()),
|
fileInfo = strings.Replace(fileInfo, "%s", humanize(curr.Size()), -1)
|
||||||
curr.ModTime().Format(gOpts.timefmt),
|
fileInfo = strings.Replace(fileInfo, "%t", curr.ModTime().Format(gOpts.timefmt), -1)
|
||||||
linkTarget)
|
fileInfo = strings.Replace(fileInfo, "%l", curr.linkTarget, -1)
|
||||||
|
fileInfo = strings.Replace(fileInfo, "%L", linkTargetArrow, -1)
|
||||||
|
ui.echo(fileInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ui *ui) drawPromptLine(nav *nav) {
|
func (ui *ui) drawPromptLine(nav *nav) {
|
||||||
|
|||||||
Reference in new issue
Block a user