Add Temporary Marks (#744)

* add temporary marks

* change option format & documentation
This commit is contained in:
Christian Zangl 2022-01-31 00:28:06 +01:00 committed by GitHub
parent 18fb632efa
commit 958857f4c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 39 additions and 5 deletions

View File

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

5
doc.go
View File

@ -137,6 +137,7 @@ The following options can be used to customize the behavior of lf:
smartdia bool (default off)
sortby string (default 'natural')
tabstop int (default 8)
tempmarks string (default '')
timefmt string (default 'Mon Jan _2 15:04:05 2006')
truncatechar string (default '~')
waitmsg string (default 'Press any key to continue')
@ -708,6 +709,10 @@ Currently supported sort types are 'natural', 'name', 'size', 'time', 'ctime', '
Number of space characters to show for horizontal tabulation (U+0009) character.
tempmarks string (default '')
A string that lists all marks to treat as temporary. They are not synced to other clients and are not saved in the bookmarks file. This option should be specified only in the global config file ("lfrc") as it may otherwise cause unintended side effects. Please note that the special bookmark "'" is always treated as temporary and does not need to be specified.
timefmt string (default 'Mon Jan _2 15:04:05 2006')
Format string of the file modification time shown in the bottom line.

View File

@ -141,6 +141,7 @@ The following options can be used to customize the behavior of lf:
smartdia bool (default off)
sortby string (default 'natural')
tabstop int (default 8)
tempmarks string (default '')
timefmt string (default 'Mon Jan _2 15:04:05 2006')
truncatechar string (default '~')
waitmsg string (default 'Press any key to continue')
@ -756,6 +757,14 @@ Sort type for directories. Currently supported sort types are 'natural',
Number of space characters to show for horizontal tabulation (U+0009)
character.
tempmarks string (default '')
A string that lists all marks to treat as temporary. They are not synced to
other clients and are not saved in the bookmarks file. This option should be
specified only in the global config file ("lfrc") as it may otherwise cause
unintended side effects. Please note that the special bookmark "'" is always
treated as temporary and does not need to be specified.
timefmt string (default 'Mon Jan _2 15:04:05 2006')
Format string of the file modification time shown in the bottom line.

View File

@ -410,6 +410,12 @@ func (e *setExpr) eval(app *app, args []string) {
}
app.nav.sort()
app.ui.sort()
case "tempmarks":
if e.val != "" {
gOpts.tempmarks = "'" + e.val
} else {
gOpts.tempmarks = "'"
}
case "timefmt":
gOpts.timefmt = e.val
case "truncatechar":

7
lf.1
View File

@ -156,6 +156,7 @@ The following options can be used to customize the behavior of lf:
smartdia bool (default off)
sortby string (default 'natural')
tabstop int (default 8)
tempmarks string (default '')
timefmt string (default 'Mon Jan _2 15:04:05 2006')
truncatechar string (default '~')
waitmsg string (default 'Press any key to continue')
@ -854,6 +855,12 @@ Sort type for directories. Currently supported sort types are 'natural', 'name',
.PP
Number of space characters to show for horizontal tabulation (U+0009) character.
.PP
.EX
tempmarks string (default '')
.EE
.PP
A string that lists all marks to treat as temporary. They are not synced to other clients and are not saved in the bookmarks file. This option should be specified only in the global config file ("lfrc") as it may otherwise cause unintended side effects. Please note that the special bookmark "'" is always treated as temporary and does not need to be specified.
.PP
.EX
timefmt string (default 'Mon Jan _2 15:04:05 2006')
.EE

12
nav.go
View File

@ -1136,12 +1136,14 @@ func (nav *nav) sync() error {
nav.saves[f] = cp
}
path, ok := nav.marks["'"]
oldmarks := nav.marks
err = nav.readMarks()
if ok {
nav.marks["'"] = path
for _, ch := range gOpts.tempmarks {
tmp := string(ch)
if v, e := oldmarks[tmp]; e {
nav.marks[tmp] = v
}
}
return err
}
@ -1419,8 +1421,10 @@ func (nav *nav) writeMarks() error {
var keys []string
for k := range nav.marks {
if !strings.Contains(gOpts.tempmarks, k) {
keys = append(keys, k)
}
}
sort.Strings(keys)
for _, k := range keys {

View File

@ -71,6 +71,7 @@ var gOpts struct {
cmdkeys map[string]expr
cmds map[string]expr
sortType sortType
tempmarks string
}
func init() {
@ -114,6 +115,7 @@ func init() {
gOpts.info = nil
gOpts.shellopts = nil
gOpts.sortType = sortType{naturalSort, dirfirstSort}
gOpts.tempmarks = "'"
gOpts.keys = make(map[string]expr)