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
This commit is contained in:
Alexey Yerin 2020-07-18 03:08:25 +03:00 committed by GitHub
parent 9880104c12
commit d0cd181eb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 9 additions and 2 deletions

View File

@ -140,6 +140,7 @@ var (
"shellopts",
"sortby",
"timefmt",
"truncatechar",
}
)

1
doc.go
View File

@ -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:

View File

@ -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:

View File

@ -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

View File

@ -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

4
ui.go
View File

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