summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCatalin Ancutei <37979489+Catalyn45@users.noreply.github.com>2024-04-07 16:36:17 +0300
committerGitHub <noreply@github.com>2024-04-07 15:36:17 +0200
commitf507b618c931592daf74f291471daeafe2410a07 (patch)
tree6f970552fa57248b8419f692e08d361c26645784
parent5b108037a309929c8f6da21bdd9750245a02bc76 (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.go2
-rw-r--r--doc.md5
-rw-r--r--doc.txt6
-rw-r--r--eval.go6
-rw-r--r--lf.15
-rw-r--r--nav.go14
-rw-r--r--opts.go2
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) + ", " +
diff --git a/doc.md b/doc.md
index faf38c9..e608e71 100644
--- a/doc.md
+++ b/doc.md
@@ -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.
diff --git a/doc.txt b/doc.txt
index 5910ce2..fd90003 100644
--- a/doc.txt
+++ b/doc.txt
@@ -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
diff --git a/eval.go b/eval.go
index be3b1c2..c3282b3 100644
--- a/eval.go
+++ b/eval.go
@@ -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 {
diff --git a/lf.1 b/lf.1
index 2bb3238..41f5f9c 100644
--- a/lf.1
+++ b/lf.1
@@ -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
diff --git a/nav.go b/nav.go
index f620222..acd2c1d 100644
--- a/nav.go
+++ b/nav.go
@@ -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
diff --git a/opts.go b/opts.go
index fc211e0..681673b 100644
--- a/opts.go
+++ b/opts.go
@@ -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