diff options
author | Catalin Ancutei <37979489+Catalyn45@users.noreply.github.com> | 2024-04-07 16:36:17 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-07 15:36:17 +0200 |
commit | f507b618c931592daf74f291471daeafe2410a07 (patch) | |
tree | 6f970552fa57248b8419f692e08d361c26645784 | |
parent | 5b108037a309929c8f6da21bdd9750245a02bc76 (diff) |
Added globfilter command (#1650)
* Added globfilter command
* Kept the alphabetical order and applied other sugestions
* Used pandoc to update docs
-rw-r--r-- | diacritics_test.go | 2 | ||||
-rw-r--r-- | doc.md | 5 | ||||
-rw-r--r-- | doc.txt | 6 | ||||
-rw-r--r-- | eval.go | 6 | ||||
-rw-r--r-- | lf.1 | 5 | ||||
-rw-r--r-- | nav.go | 14 | ||||
-rw-r--r-- | opts.go | 2 |
7 files changed, 30 insertions, 10 deletions
diff --git a/diacritics_test.go b/diacritics_test.go index 3e29cf2..1d71eea 100644 --- a/diacritics_test.go +++ b/diacritics_test.go @@ -61,7 +61,7 @@ func runSearch(t *testing.T, ignorecase, smartcase, ignorediacritics, smartdiacr gOpts.smartcase = smartcase gOpts.ignoredia = ignorediacritics gOpts.smartdia = smartdiacritics - matched, _ := searchMatch(base, pattern) + matched, _ := searchMatch(base, pattern, false) if matched != expected { t.Errorf("False search for" + " ignorecase = " + strconv.FormatBool(gOpts.ignorecase) + ", " + @@ -155,6 +155,7 @@ The following options can be used to customize the behavior of lf: errorfmt string (default "\033[7;31;47m") filesep string (default "\n") findlen int (default 1) + globfilter bool (default false) globsearch bool (default false) hidden bool (default false) hiddenfiles []string (default '.*') @@ -749,6 +750,10 @@ File separator used in environment variables `fs` and `fx`. Number of characters prompted for the find command. When this value is set to 0, find command prompts until there is only a single match left. +## globfilter (bool) (default false) + +Patterns are treated as globs for the filter command, see `globsearch` for more details. + ## globsearch (bool) (default false) When this option is enabled, search command patterns are considered as globs, otherwise, they are literals. @@ -145,6 +145,7 @@ The following options can be used to customize the behavior of lf: errorfmt string (default "\033[7;31;47m") filesep string (default "\n") findlen int (default 1) + globfilter bool (default false) globsearch bool (default false) hidden bool (default false) hiddenfiles []string (default '.*') @@ -797,6 +798,11 @@ findlen (int) (default 1) Number of characters prompted for the find command. When this value is set to 0, find command prompts until there is only a single match left. +globfilter (bool) (default false) + +Patterns are treated as globs for the filter command, see globsearch for +more details. + globsearch (bool) (default false) When this option is enabled, search command patterns are considered as @@ -96,14 +96,16 @@ func (e *setExpr) eval(app *app, args []string) { } app.ui.loadFile(app, true) } - case "globsearch", "noglobsearch", "globsearch!": - err = applyBoolOpt(&gOpts.globsearch, e) + case "globfilter", "noglobfilter", "globfilter!": + err = applyBoolOpt(&gOpts.globfilter, e) if err == nil { app.nav.sort() app.nav.position() app.ui.sort() app.ui.loadFile(app, true) } + case "globsearch", "noglobsearch", "globsearch!": + err = applyBoolOpt(&gOpts.globsearch, e) case "hidden", "nohidden", "hidden!": err = applyBoolOpt(&gOpts.hidden, e) if err == nil { @@ -163,6 +163,7 @@ dupfilefmt string (default \[aq]%f.\[ti]%n\[ti]\[aq]) errorfmt string (default \[dq]\[rs]033[7;31;47m\[dq]) filesep string (default \[dq]\[rs]n\[dq]) findlen int (default 1) +globfilter bool (default false) globsearch bool (default false) hidden bool (default false) hiddenfiles []string (default \[aq].*\[aq]) @@ -815,6 +816,10 @@ File separator used in environment variables \f[C]fs\f[R] and Number of characters prompted for the find command. When this value is set to 0, find command prompts until there is only a single match left. +.SS globfilter (bool) (default false) +.PP +Patterns are treated as globs for the filter command, see +\f[C]globsearch\f[R] for more details. .SS globsearch (bool) (default false) .PP When this option is enabled, search command patterns are considered as @@ -1756,7 +1756,7 @@ func (nav *nav) findPrev() (bool, bool) { return false, false } -func searchMatch(name, pattern string) (matched bool, err error) { +func searchMatch(name, pattern string, glob bool) (matched bool, err error) { if gOpts.ignorecase { lpattern := strings.ToLower(pattern) if !gOpts.smartcase || lpattern == pattern { @@ -1771,7 +1771,7 @@ func searchMatch(name, pattern string) (matched bool, err error) { name = removeDiacritics(name) } } - if gOpts.globsearch { + if glob { return filepath.Match(pattern, name) } return strings.Contains(name, pattern), nil @@ -1780,7 +1780,7 @@ func searchMatch(name, pattern string) (matched bool, err error) { func (nav *nav) searchNext() (bool, error) { dir := nav.currDir() for i := dir.ind + 1; i < len(dir.files); i++ { - if matched, err := searchMatch(dir.files[i].Name(), nav.search); err != nil { + if matched, err := searchMatch(dir.files[i].Name(), nav.search, gOpts.globsearch); err != nil { return false, err } else if matched { return nav.down(i - dir.ind), nil @@ -1788,7 +1788,7 @@ func (nav *nav) searchNext() (bool, error) { } if gOpts.wrapscan { for i := 0; i < dir.ind; i++ { - if matched, err := searchMatch(dir.files[i].Name(), nav.search); err != nil { + if matched, err := searchMatch(dir.files[i].Name(), nav.search, gOpts.globsearch); err != nil { return false, err } else if matched { return nav.up(dir.ind - i), nil @@ -1801,7 +1801,7 @@ func (nav *nav) searchNext() (bool, error) { func (nav *nav) searchPrev() (bool, error) { dir := nav.currDir() for i := dir.ind - 1; i >= 0; i-- { - if matched, err := searchMatch(dir.files[i].Name(), nav.search); err != nil { + if matched, err := searchMatch(dir.files[i].Name(), nav.search, gOpts.globsearch); err != nil { return false, err } else if matched { return nav.up(dir.ind - i), nil @@ -1809,7 +1809,7 @@ func (nav *nav) searchPrev() (bool, error) { } if gOpts.wrapscan { for i := len(dir.files) - 1; i > dir.ind; i-- { - if matched, err := searchMatch(dir.files[i].Name(), nav.search); err != nil { + if matched, err := searchMatch(dir.files[i].Name(), nav.search, gOpts.globsearch); err != nil { return false, err } else if matched { return nav.down(i - dir.ind), nil @@ -1821,7 +1821,7 @@ func (nav *nav) searchPrev() (bool, error) { func isFiltered(f os.FileInfo, filter []string) bool { for _, pattern := range filter { - matched, err := searchMatch(f.Name(), strings.TrimPrefix(pattern, "!")) + matched, err := searchMatch(f.Name(), strings.TrimPrefix(pattern, "!"), gOpts.globfilter) if err != nil { log.Printf("Filter Error: %s", err) return false @@ -46,6 +46,7 @@ var gOpts struct { dirpreviews bool drawbox bool dupfilefmt string + globfilter bool globsearch bool hidden bool icons bool @@ -191,6 +192,7 @@ func init() { gOpts.cursorpreviewfmt = "\033[4m" gOpts.cutfmt = "\033[7;31m" gOpts.hidecursorinactive = false + gOpts.globfilter = false gOpts.globsearch = false gOpts.hidden = false gOpts.icons = false |