diff --git a/complete.go b/complete.go index 024da3a0..cae50828 100644 --- a/complete.go +++ b/complete.go @@ -211,6 +211,7 @@ var ( "shellflag", "shellopts", "sortby", + "statfmt", "timefmt", "tempmarks", "tagfmt", diff --git a/doc.go b/doc.go index bdafebe4..806b6aac 100644 --- a/doc.go +++ b/doc.go @@ -166,6 +166,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") tabstop int (default 8) tagfmt string (default "\033[31m") tempmarks string (default '') @@ -909,6 +910,12 @@ 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") + +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) Number of space characters to show for horizontal tabulation (U+0009) character. diff --git a/docstring.go b/docstring.go index 89476715..61692de5 100644 --- a/docstring.go +++ b/docstring.go @@ -169,6 +169,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") tabstop int (default 8) tagfmt string (default "\033[31m") 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', '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) Number of space characters to show for horizontal tabulation (U+0009) character. diff --git a/eval.go b/eval.go index 863d4f0c..24975c3c 100644 --- a/eval.go +++ b/eval.go @@ -801,6 +801,8 @@ func (e *setExpr) eval(app *app, args []string) { } app.nav.sort() app.ui.sort() + case "statfmt": + gOpts.statfmt = e.val case "tabstop": n, err := strconv.Atoi(e.val) if err != nil { diff --git a/lf.1 b/lf.1 index 7b59b1c5..561edc59 100644 --- a/lf.1 +++ b/lf.1 @@ -185,6 +185,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") tabstop int (default 8) tagfmt string (default "\e033[31m") tempmarks string (default '') @@ -1080,6 +1081,12 @@ Override 'ignoredia' option when the pattern contains a character with diacritic .PP 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") +.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 tabstop int (default 8) .EE diff --git a/opts.go b/opts.go index 58c1532c..21d624c4 100644 --- a/opts.go +++ b/opts.go @@ -67,6 +67,7 @@ var gOpts struct { selmode string shell string shellflag string + statfmt string timefmt string infotimefmtnew string infotimefmtold string diff --git a/os.go b/os.go index a0ae9fda..d26b9f1f 100644 --- a/os.go +++ b/os.go @@ -10,6 +10,7 @@ import ( "os/user" "path/filepath" "runtime" + "strconv" "strings" "syscall" @@ -164,6 +165,8 @@ func setDefaults() { gOpts.cmds["doc"] = &execExpr{"$", `"$lf" -doc | $PAGER`} gOpts.keys[""] = &callExpr{"doc", nil, 1} + + gOpts.statfmt = "\033[36m%p\033[0m %c %u %g %s %t %L" } func setUserUmask() { @@ -190,7 +193,7 @@ func isHidden(f os.FileInfo, path string, hiddenfiles []string) bool { func userName(f os.FileInfo) string { if stat, ok := f.Sys().(*syscall.Stat_t); ok { if u, err := user.LookupId(fmt.Sprint(stat.Uid)); err == nil { - return fmt.Sprintf("%v ", u.Username) + return u.Username } } return "" @@ -199,7 +202,7 @@ func userName(f os.FileInfo) string { func groupName(f os.FileInfo) string { if stat, ok := f.Sys().(*syscall.Stat_t); ok { if g, err := user.LookupGroupId(fmt.Sprint(stat.Gid)); err == nil { - return fmt.Sprintf("%v ", g.Name) + return g.Name } } return "" @@ -207,7 +210,7 @@ func groupName(f os.FileInfo) string { func linkCount(f os.FileInfo) string { if stat, ok := f.Sys().(*syscall.Stat_t); ok { - return fmt.Sprintf("%v ", stat.Nlink) + return strconv.FormatUint(stat.Nlink, 10) } return "" } diff --git a/os_windows.go b/os_windows.go index b79d99e5..ff9ac4bd 100644 --- a/os_windows.go +++ b/os_windows.go @@ -123,6 +123,8 @@ func setDefaults() { gOpts.cmds["doc"] = &execExpr{"!", "%lf% -doc | %PAGER%"} gOpts.keys[""] = &callExpr{"doc", nil, 1} + + gOpts.statfmt = "\033[36m%p\033[0m %s %t %L" } func setUserUmask() {} diff --git a/ui.go b/ui.go index 1f8af2c1..635a4281 100644 --- a/ui.go +++ b/ui.go @@ -648,10 +648,6 @@ func (ui *ui) echo(msg string) { ui.msg = msg } -func (ui *ui) echof(format string, a ...interface{}) { - ui.echo(fmt.Sprintf(format, a...)) -} - func (ui *ui) echomsg(msg string) { ui.msg = msg log.Print(msg) @@ -722,19 +718,21 @@ func (ui *ui) loadFileInfo(nav *nav) { return } - var linkTarget string + linkTargetArrow := "" if curr.linkTarget != "" { - linkTarget = " -> " + curr.linkTarget + linkTargetArrow = "-> " + curr.linkTarget } - ui.echof("%v %v%v%v%4s %v%s", - curr.Mode(), - linkCount(curr), // optional - userName(curr), // optional - groupName(curr), // optional - humanize(curr.Size()), - curr.ModTime().Format(gOpts.timefmt), - 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) + ui.echo(fileInfo) } func (ui *ui) drawPromptLine(nav *nav) {