From d0cd181eb6db2df0942d28a408ccce9417902265 Mon Sep 17 00:00:00 2001 From: Alexey Yerin Date: Sat, 18 Jul 2020 03:08:25 +0300 Subject: [PATCH] Ability to customize filename truncating (#417) * Add truncatechar option * Add ability to set truncatechar via `set` command * Add completion for truncatechar option * Actually use truncatechar option when truncating * Add truncatechar option to docs --- complete.go | 1 + doc.go | 1 + docstring.go | 1 + eval.go | 2 ++ opts.go | 2 ++ ui.go | 4 ++-- 6 files changed, 9 insertions(+), 2 deletions(-) diff --git a/complete.go b/complete.go index e8d0725..5cb24dd 100644 --- a/complete.go +++ b/complete.go @@ -140,6 +140,7 @@ var ( "shellopts", "sortby", "timefmt", + "truncatechar", } ) diff --git a/doc.go b/doc.go index 58ab19e..cd532ed 100644 --- a/doc.go +++ b/doc.go @@ -136,6 +136,7 @@ The following options can be used to customize the behavior of lf: shellopts string (default '') sortby string (default 'natural') timefmt string (default 'Mon Jan _2 15:04:05 2006') + truncatechar string (default '~') The following variables are exported for shell commands: diff --git a/docstring.go b/docstring.go index 576a4a3..dd6ddb3 100644 --- a/docstring.go +++ b/docstring.go @@ -139,6 +139,7 @@ The following options can be used to customize the behavior of lf: shellopts string (default '') sortby string (default 'natural') timefmt string (default 'Mon Jan _2 15:04:05 2006') + truncatechar string (default '~') The following variables are exported for shell commands: diff --git a/eval.go b/eval.go index 4c2bf8b..6a0957c 100644 --- a/eval.go +++ b/eval.go @@ -314,6 +314,8 @@ func (e *setExpr) eval(app *app, args []string) { app.ui.sort() case "timefmt": gOpts.timefmt = e.val + case "truncatechar": + gOpts.truncatechar = e.val default: app.ui.echoerrf("unknown option: %s", e.opt) return diff --git a/opts.go b/opts.go index 4a32df9..d71833e 100644 --- a/opts.go +++ b/opts.go @@ -55,6 +55,7 @@ var gOpts struct { promptfmt string shell string timefmt string + truncatechar string ratios []int hiddenfiles []string info []string @@ -93,6 +94,7 @@ func init() { gOpts.promptfmt = "\033[32;1m%u@%h\033[0m:\033[34;1m%w/\033[0m\033[1m%f\033[0m" gOpts.shell = gDefaultShell gOpts.timefmt = time.ANSIC + gOpts.truncatechar = "~" gOpts.ratios = []int{1, 2, 3} gOpts.hiddenfiles = []string{".*"} gOpts.info = nil diff --git a/ui.go b/ui.go index 8dd7f2e..b036394 100644 --- a/ui.go +++ b/ui.go @@ -345,7 +345,7 @@ func (win *win) printDir(dir *dir, selections map[string]int, saves map[string]b if w > win.w-3 { s = runeSliceWidthRange(s, 0, win.w-4) - s = append(s, '~') + s = append(s, []rune(gOpts.truncatechar)...) } else { for i := 0; i < win.w-3-w; i++ { s = append(s, ' ') @@ -359,7 +359,7 @@ func (win *win) printDir(dir *dir, selections map[string]int, saves map[string]b s = runeSliceWidthRange(s, 0, win.w-3-len(info)-lnwidth) } else { s = runeSliceWidthRange(s, 0, win.w-4-len(info)-lnwidth) - s = append(s, '~') + s = append(s, []rune(gOpts.truncatechar)...) } for _, r := range info { s = append(s, r)