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", "reverse",
"noreverse", "noreverse",
"reverse!", "reverse!",
"smartcase",
"nosmartcase",
"smartcase!",
"wrapscan", "wrapscan",
"nowrapscan", "nowrapscan",
"wrapscan!", "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) ignorecase boolean (default off)
preview boolean (default on) preview boolean (default on)
reverse boolean (default off) reverse boolean (default off)
smartcase boolean (default off)
wrapscan boolean (default on) wrapscan boolean (default on)
scrolloff integer (default 0) scrolloff integer (default 0)
tabstop integer (default 8) 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) ignorecase boolean (default off)
preview boolean (default on) preview boolean (default on)
reverse boolean (default off) reverse boolean (default off)
smartcase boolean (default off)
wrapscan boolean (default on) wrapscan boolean (default on)
scrolloff integer (default 0) scrolloff integer (default 0)
tabstop integer (default 8) tabstop integer (default 8)

View File

@ -62,6 +62,12 @@ func (e *setExpr) eval(app *app, args []string) {
case "reverse!": case "reverse!":
gOpts.reverse = !gOpts.reverse gOpts.reverse = !gOpts.reverse
app.nav.renew(app.nav.height) app.nav.renew(app.nav.height)
case "smartcase":
gOpts.smartcase = true
case "nosmartcase":
gOpts.smartcase = false
case "smartcase!":
gOpts.smartcase = !gOpts.smartcase
case "wrapscan": case "wrapscan":
gOpts.wrapscan = true gOpts.wrapscan = true
case "nowrapscan": 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) { func match(pattern, name string) (matched bool, err error) {
if gOpts.ignorecase { 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 { if gOpts.globsearch {
return filepath.Match(pattern, name) return filepath.Match(pattern, name)

View File

@ -10,6 +10,7 @@ var gOpts struct {
ignorecase bool ignorecase bool
preview bool preview bool
reverse bool reverse bool
smartcase bool
wrapscan bool wrapscan bool
scrolloff int scrolloff int
tabstop int tabstop int
@ -34,6 +35,7 @@ func init() {
gOpts.ignorecase = false gOpts.ignorecase = false
gOpts.preview = true gOpts.preview = true
gOpts.reverse = false gOpts.reverse = false
gOpts.smartcase = false
gOpts.wrapscan = true gOpts.wrapscan = true
gOpts.scrolloff = 0 gOpts.scrolloff = 0
gOpts.tabstop = 8 gOpts.tabstop = 8