From cb072eba125749e416f4d9d8634a367b2c56041d Mon Sep 17 00:00:00 2001 From: Gokcehan Date: Sat, 15 Jul 2017 17:46:22 +0300 Subject: [PATCH] add smartcase option for smart case sensitive search Mentioned in #69. --- comp.go | 3 +++ doc.go | 1 + docstring.go | 1 + eval.go | 6 ++++++ nav.go | 6 +++++- opts.go | 2 ++ 6 files changed, 18 insertions(+), 1 deletion(-) diff --git a/comp.go b/comp.go index cb67ae0..cb6bf36 100644 --- a/comp.go +++ b/comp.go @@ -68,6 +68,9 @@ var ( "reverse", "noreverse", "reverse!", + "smartcase", + "nosmartcase", + "smartcase!", "wrapscan", "nowrapscan", "wrapscan!", diff --git a/doc.go b/doc.go index 132b5db..a7facdc 100644 --- a/doc.go +++ b/doc.go @@ -75,6 +75,7 @@ The following options can be used to customize the behavior of lf: ignorecase boolean (default off) preview boolean (default on) reverse boolean (default off) + smartcase boolean (default off) wrapscan boolean (default on) scrolloff integer (default 0) tabstop integer (default 8) diff --git a/docstring.go b/docstring.go index 8eb2ed9..c777f42 100644 --- a/docstring.go +++ b/docstring.go @@ -79,6 +79,7 @@ The following options can be used to customize the behavior of lf: ignorecase boolean (default off) preview boolean (default on) reverse boolean (default off) + smartcase boolean (default off) wrapscan boolean (default on) scrolloff integer (default 0) tabstop integer (default 8) diff --git a/eval.go b/eval.go index 0b02677..a08d931 100644 --- a/eval.go +++ b/eval.go @@ -62,6 +62,12 @@ func (e *setExpr) eval(app *app, args []string) { case "reverse!": gOpts.reverse = !gOpts.reverse app.nav.renew(app.nav.height) + case "smartcase": + gOpts.smartcase = true + case "nosmartcase": + gOpts.smartcase = false + case "smartcase!": + gOpts.smartcase = !gOpts.smartcase case "wrapscan": gOpts.wrapscan = true case "nowrapscan": diff --git a/nav.go b/nav.go index d17f68d..93bfdde 100644 --- a/nav.go +++ b/nav.go @@ -370,7 +370,11 @@ func (nav *nav) cd(wd string) error { func match(pattern, name string) (matched bool, err error) { if gOpts.ignorecase { - pattern, name = strings.ToLower(pattern), strings.ToLower(name) + lpattern := strings.ToLower(pattern) + if !gOpts.smartcase || lpattern == pattern { + pattern = lpattern + name = strings.ToLower(name) + } } if gOpts.globsearch { return filepath.Match(pattern, name) diff --git a/opts.go b/opts.go index da5d56a..a3ceef5 100644 --- a/opts.go +++ b/opts.go @@ -10,6 +10,7 @@ var gOpts struct { ignorecase bool preview bool reverse bool + smartcase bool wrapscan bool scrolloff int tabstop int @@ -34,6 +35,7 @@ func init() { gOpts.ignorecase = false gOpts.preview = true gOpts.reverse = false + gOpts.smartcase = false gOpts.wrapscan = true gOpts.scrolloff = 0 gOpts.tabstop = 8