From 958857f4c49c74704db7ae2435b8e01d3a378463 Mon Sep 17 00:00:00 2001 From: Christian Zangl Date: Mon, 31 Jan 2022 00:28:06 +0100 Subject: [PATCH] Add Temporary Marks (#744) * add temporary marks * change option format & documentation --- complete.go | 1 + doc.go | 5 +++++ docstring.go | 9 +++++++++ eval.go | 6 ++++++ lf.1 | 7 +++++++ nav.go | 14 +++++++++----- opts.go | 2 ++ 7 files changed, 39 insertions(+), 5 deletions(-) diff --git a/complete.go b/complete.go index 00ed30c..b233679 100644 --- a/complete.go +++ b/complete.go @@ -157,6 +157,7 @@ var ( "shellopts", "sortby", "timefmt", + "tempmarks", "truncatechar", } ) diff --git a/doc.go b/doc.go index 3e180da..c6b0acf 100644 --- a/doc.go +++ b/doc.go @@ -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. diff --git a/docstring.go b/docstring.go index cd100dc..e7880b5 100644 --- a/docstring.go +++ b/docstring.go @@ -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. diff --git a/eval.go b/eval.go index 6dd87b6..f8d3204 100644 --- a/eval.go +++ b/eval.go @@ -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": diff --git a/lf.1 b/lf.1 index b2117e9..91cbbf0 100644 --- a/lf.1 +++ b/lf.1 @@ -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 diff --git a/nav.go b/nav.go index 79838e4..1330b1e 100644 --- a/nav.go +++ b/nav.go @@ -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,7 +1421,9 @@ func (nav *nav) writeMarks() error { var keys []string for k := range nav.marks { - keys = append(keys, k) + if !strings.Contains(gOpts.tempmarks, k) { + keys = append(keys, k) + } } sort.Strings(keys) diff --git a/opts.go b/opts.go index 724c93d..e2a1d14 100644 --- a/opts.go +++ b/opts.go @@ -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)