add smartcase option for smart case sensitive search

Mentioned in #69.
This commit is contained in:
Gokcehan 2017-07-15 17:46:22 +03:00
parent ca7a3ccab4
commit cb072eba12
6 changed files with 18 additions and 1 deletions

View File

@ -68,6 +68,9 @@ var (
"reverse",
"noreverse",
"reverse!",
"smartcase",
"nosmartcase",
"smartcase!",
"wrapscan",
"nowrapscan",
"wrapscan!",

1
doc.go
View File

@ -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)

View File

@ -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)

View File

@ -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":

6
nav.go
View File

@ -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)

View File

@ -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