From ca7a3ccab4874931e8d302e73283b45c5737f5c2 Mon Sep 17 00:00:00 2001 From: Gokcehan Date: Sat, 15 Jul 2017 17:18:37 +0300 Subject: [PATCH] add ignorecase option for case insensitive search Mentioned in #69. --- comp.go | 3 +++ doc.go | 1 + docstring.go | 1 + eval.go | 6 ++++++ nav.go | 3 +++ opts.go | 2 ++ 6 files changed, 16 insertions(+) diff --git a/comp.go b/comp.go index 538ab3c..cb67ae0 100644 --- a/comp.go +++ b/comp.go @@ -59,6 +59,9 @@ var ( "hidden", "nohidden", "hidden!", + "ignorecase", + "noignorecase", + "ignorecase!", "preview", "nopreview", "preview!", diff --git a/doc.go b/doc.go index 2dacacb..132b5db 100644 --- a/doc.go +++ b/doc.go @@ -72,6 +72,7 @@ The following options can be used to customize the behavior of lf: dirfirst boolean (default on) globsearch boolean (default off) hidden boolean (default off) + ignorecase boolean (default off) preview boolean (default on) reverse boolean (default off) wrapscan boolean (default on) diff --git a/docstring.go b/docstring.go index adfc0db..8eb2ed9 100644 --- a/docstring.go +++ b/docstring.go @@ -76,6 +76,7 @@ The following options can be used to customize the behavior of lf: dirfirst boolean (default on) globsearch boolean (default off) hidden boolean (default off) + ignorecase boolean (default off) preview boolean (default on) reverse boolean (default off) wrapscan boolean (default on) diff --git a/eval.go b/eval.go index 34956a2..0b02677 100644 --- a/eval.go +++ b/eval.go @@ -41,6 +41,12 @@ func (e *setExpr) eval(app *app, args []string) { case "hidden!": gOpts.hidden = !gOpts.hidden app.nav.renew(app.nav.height) + case "ignorecase": + gOpts.ignorecase = true + case "noignorecase": + gOpts.ignorecase = false + case "ignorecase!": + gOpts.ignorecase = !gOpts.ignorecase case "preview": gOpts.preview = true case "nopreview": diff --git a/nav.go b/nav.go index 9573cc3..d17f68d 100644 --- a/nav.go +++ b/nav.go @@ -369,6 +369,9 @@ 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) + } if gOpts.globsearch { return filepath.Match(pattern, name) } else { diff --git a/opts.go b/opts.go index 43a4a45..da5d56a 100644 --- a/opts.go +++ b/opts.go @@ -7,6 +7,7 @@ var gOpts struct { dirfirst bool globsearch bool hidden bool + ignorecase bool preview bool reverse bool wrapscan bool @@ -30,6 +31,7 @@ func init() { gOpts.dirfirst = true gOpts.globsearch = false gOpts.hidden = false + gOpts.ignorecase = false gOpts.preview = true gOpts.reverse = false gOpts.wrapscan = true