From 4420e41c760b220d465041753bc426b9c2650c68 Mon Sep 17 00:00:00 2001 From: Gokcehan Date: Thu, 23 Aug 2018 01:37:07 +0300 Subject: [PATCH] add 'anchorfind' option to control find start Related #68 --- complete.go | 3 +++ doc.go | 1 + docstring.go | 1 + eval.go | 6 ++++++ lf.1 | 1 + nav.go | 5 ++++- opts.go | 2 ++ 7 files changed, 18 insertions(+), 1 deletion(-) diff --git a/complete.go b/complete.go index 47c4ebc4..d2b7720a 100644 --- a/complete.go +++ b/complete.go @@ -60,6 +60,9 @@ var ( } gOptWords = []string{ + "anchorfind", + "noanchorfind", + "anchorfind!", "dircounts", "nodircounts", "dircounts!", diff --git a/doc.go b/doc.go index aa338b0f..f134d214 100644 --- a/doc.go +++ b/doc.go @@ -93,6 +93,7 @@ keybindings: The following options can be used to customize the behavior of lf: + anchorfind boolean (default on) dircounts boolean (default off) dirfirst boolean (default on) drawbox boolean (default off) diff --git a/docstring.go b/docstring.go index 6cdc19de..2ce3d58e 100644 --- a/docstring.go +++ b/docstring.go @@ -96,6 +96,7 @@ keybindings: The following options can be used to customize the behavior of lf: + anchorfind boolean (default on) dircounts boolean (default off) dirfirst boolean (default on) drawbox boolean (default off) diff --git a/eval.go b/eval.go index 3f53740b..a6eb25e9 100644 --- a/eval.go +++ b/eval.go @@ -14,6 +14,12 @@ import ( func (e *setExpr) eval(app *app, args []string) { switch e.opt { + case "anchorfind": + gOpts.anchorfind = true + case "noanchorfind": + gOpts.anchorfind = false + case "anchorfind!": + gOpts.anchorfind = !gOpts.anchorfind case "dircounts": gOpts.dircounts = true case "nodircounts": diff --git a/lf.1 b/lf.1 index 887a2d6c..72454cc2 100644 --- a/lf.1 +++ b/lf.1 @@ -108,6 +108,7 @@ The following command line commands are provided by lf with default keybindings: The following options can be used to customize the behavior of lf: .PP .EX + anchorfind boolean (default on) dircounts boolean (default off) dirfirst boolean (default on) drawbox boolean (default off) diff --git a/nav.go b/nav.go index 0f323606..674535aa 100644 --- a/nav.go +++ b/nav.go @@ -663,7 +663,10 @@ func findMatch(name, pattern string) bool { name = strings.ToLower(name) } } - return strings.HasPrefix(name, pattern) + if gOpts.anchorfind { + return strings.HasPrefix(name, pattern) + } + return strings.Contains(name, pattern) } func (nav *nav) findSingle() int { diff --git a/opts.go b/opts.go index 496d8acc..f1c53b3c 100644 --- a/opts.go +++ b/opts.go @@ -25,6 +25,7 @@ type sortType struct { } var gOpts struct { + anchorfind bool dircounts bool drawbox bool globsearch bool @@ -52,6 +53,7 @@ var gOpts struct { } func init() { + gOpts.anchorfind = true gOpts.dircounts = false gOpts.drawbox = false gOpts.globsearch = false