diff --git a/doc.md b/doc.md index b8d40d74..dd9fb99b 100644 --- a/doc.md +++ b/doc.md @@ -316,6 +316,8 @@ The following options can be used to customize the behavior of lf: smartcase bool (default true) smartdia bool (default false) sortby string (default 'natural') + sortignorecase bool (default true) + sortignoredia bool (default true) statfmt string (default "\033[36m%p\033[0m| %c| %u| %g| %S| %t| -> %l") tabstop int (default 8) tagfmt string (default "\033[31m") @@ -981,11 +983,11 @@ This option does not have any effect on Windows. ## ignorecase (bool) (default true) -Ignore case in sorting and search patterns. +Ignore case in search patterns. See also `sortignorecase`. ## ignoredia (bool) (default true) -Ignore diacritics in sorting and search patterns. +Ignore diacritics in search patterns. See also `sortignoredia`. ## incfilter (bool) (default false) @@ -1197,7 +1199,7 @@ Determines whether file sizes are displayed using binary units (`1K` is 1024 byt ## smartcase (bool) (default true) -Override `ignorecase` option when the pattern contains an uppercase character. +Override `ignorecase` option for searching when the pattern contains an uppercase character. This option has no effect when `ignorecase` is disabled. ## smartdia (bool) (default false) @@ -1221,6 +1223,14 @@ The following sort types are supported: ctime time of last status (inode) change custom property defined via `addcustominfo` (empty by default) +## sortignorecase (bool) (default true) + +Ignore case when sorting. See also `ignorecase`. + +## sortignoredia (bool) (default true) + +Ignore diacritics when sorting. See also `ignoredia`. + ## statfmt (string) (default `\033[36m%p\033[0m| %c| %u| %g| %S| %t| -> %l`) Format string of the file info shown in the bottom left corner. @@ -1494,7 +1504,7 @@ Command `set` is used to set an option which can be a boolean, integer, or strin set sortby "time" # string value with double quotes (backslash escapes) Command `setlocal` is used to set a local option for a directory which can be a boolean or string. -Currently supported local options are `dircounts`, `dirfirst`, `dironly`, `hidden`, `info`, `reverse` and `sortby`. +Currently supported local options are `dircounts`, `dirfirst`, `dironly`, `hidden`, `info`, `reverse`, `sortby`, `sortignorecase` and `sortignoredia`. setlocal /foo/bar hidden # boolean enable setlocal /foo/bar hidden true # boolean enable diff --git a/doc.txt b/doc.txt index 1c7321de..0c5cbb2f 100644 --- a/doc.txt +++ b/doc.txt @@ -328,6 +328,8 @@ The following options can be used to customize the behavior of lf: smartcase bool (default true) smartdia bool (default false) sortby string (default 'natural') + sortignorecase bool (default true) + sortignoredia bool (default true) statfmt string (default "\033[36m%p\033[0m| %c| %u| %g| %S| %t| -> %l") tabstop int (default 8) tagfmt string (default "\033[31m") @@ -1059,11 +1061,11 @@ option does not have any effect on Windows. ignorecase (bool) (default true) -Ignore case in sorting and search patterns. +Ignore case in search patterns. See also sortignorecase. ignoredia (bool) (default true) -Ignore diacritics in sorting and search patterns. +Ignore diacritics in search patterns. See also sortignoredia. incfilter (bool) (default false) @@ -1304,8 +1306,9 @@ Determines whether file sizes are displayed using binary units (1K is smartcase (bool) (default true) -Override ignorecase option when the pattern contains an uppercase -character. This option has no effect when ignorecase is disabled. +Override ignorecase option for searching when the pattern contains an +uppercase character. This option has no effect when ignorecase is +disabled. smartdia (bool) (default false) @@ -1328,6 +1331,14 @@ The following sort types are supported: ctime time of last status (inode) change custom property defined via `addcustominfo` (empty by default) +sortignorecase (bool) (default true) + +Ignore case when sorting. See also ignorecase. + +sortignoredia (bool) (default true) + +Ignore diacritics when sorting. See also ignoredia. + statfmt (string) (default \033[36m%p\033[0m| %c| %u| %g| %S| %t| -> %l) Format string of the file info shown in the bottom left corner. This @@ -1643,7 +1654,8 @@ string: Command setlocal is used to set a local option for a directory which can be a boolean or string. Currently supported local options are dircounts, -dirfirst, dironly, hidden, info, reverse and sortby. +dirfirst, dironly, hidden, info, reverse, sortby, sortignorecase and +sortignoredia. setlocal /foo/bar hidden # boolean enable setlocal /foo/bar hidden true # boolean enable diff --git a/eval.go b/eval.go index 28030600..cb24d01b 100644 --- a/eval.go +++ b/eval.go @@ -173,6 +173,16 @@ func (e *setExpr) eval(app *app, _ []string) { app.nav.position() app.ui.loadFile(app, true) } + case "sortignorecase", "nosortignorecase", "sortignorecase!": + err = applyBoolOpt(&gOpts.sortignorecase, e) + if err == nil { + app.nav.sort() + } + case "sortignoredia", "nosortignoredia", "sortignoredia!": + err = applyBoolOpt(&gOpts.sortignoredia, e) + if err == nil { + app.nav.sort() + } case "watch", "nowatch", "watch!": err = applyBoolOpt(&gOpts.watch, e) if err == nil { @@ -534,6 +544,16 @@ func (e *setLocalExpr) eval(app *app, _ []string) { if err == nil { app.nav.sort() } + case "sortignorecase", "nosortignorecase", "sortignorecase!": + err = applyLocalBoolOpt(gLocalOpts.sortignorecase, gOpts.sortignorecase, e) + if err == nil { + app.nav.sort() + } + case "sortignoredia", "nosortignoredia", "sortignoredia!": + err = applyLocalBoolOpt(gLocalOpts.sortignoredia, gOpts.sortignoredia, e) + if err == nil { + app.nav.sort() + } case "info": if e.val == "" { gLocalOpts.info[e.path] = nil diff --git a/nav.go b/nav.go index 4653f7e6..75993b11 100644 --- a/nav.go +++ b/nav.go @@ -162,26 +162,26 @@ func readdir(path string) ([]*file, error) { } type dir struct { - loading bool // whether directory is loading from disk - loadTime time.Time // last load time - ind int // 0-based index of current entry in dir.files - pos int // 0-based cursor row in directory window - path string // full path of directory - files []*file // displayed files in directory including or excluding hidden ones - allFiles []*file // all files in directory including hidden ones (same array as files) - sortby sortMethod // sortby value from last sort - dircounts bool // dircounts value from last sort - dirfirst bool // dirfirst value from last sort - dironly bool // dironly value from last sort - hidden bool // hidden value from last sort - reverse bool // reverse value from last sort - visualAnchor int // index where Visual mode was initiated - visualWrap int // wrap direction in Visual mode (0: none, +: bottom->top, -: top->bottom) - hiddenfiles []string // hiddenfiles value from last sort - filter []string // last filter for this directory - ignorecase bool // ignorecase value from last sort - ignoredia bool // ignoredia value from last sort - noPerm bool // whether lf has no permission to open the directory + loading bool // whether directory is loading from disk + loadTime time.Time // last load time + ind int // 0-based index of current entry in dir.files + pos int // 0-based cursor row in directory window + path string // full path of directory + files []*file // displayed files in directory including or excluding hidden ones + allFiles []*file // all files in directory including hidden ones (same array as files) + sortby sortMethod // sortby value from last sort + dircounts bool // dircounts value from last sort + dirfirst bool // dirfirst value from last sort + dironly bool // dironly value from last sort + hidden bool // hidden value from last sort + reverse bool // reverse value from last sort + visualAnchor int // index where Visual mode was initiated + visualWrap int // wrap direction in Visual mode (0: none, +: bottom->top, -: top->bottom) + hiddenfiles []string // hiddenfiles value from last sort + filter []string // last filter for this directory + sortignorecase bool // sortignorecase value from last sort + sortignoredia bool // sortignoredia value from last sort + noPerm bool // whether lf has no permission to open the directory } func newDir(path string) *dir { @@ -208,8 +208,8 @@ func (dir *dir) sort() { dir.hidden = getHidden(dir.path) dir.reverse = getReverse(dir.path) dir.hiddenfiles = gOpts.hiddenfiles - dir.ignorecase = gOpts.ignorecase - dir.ignoredia = gOpts.ignoredia + dir.sortignorecase = getSortIgnoreCase(dir.path) + dir.sortignoredia = getSortIgnoreDia(dir.path) dir.files = dir.allFiles @@ -256,10 +256,10 @@ func (dir *dir) sort() { } normalize := func(s string) string { - if dir.ignorecase { + if dir.sortignorecase { s = strings.ToLower(s) } - if dir.ignoredia { + if dir.sortignoredia { s = removeDiacritics(s) } return s @@ -491,19 +491,19 @@ func (nav *nav) getDir(path string) *dir { }() d := &dir{ - loading: true, - loadTime: time.Now(), - path: path, - sortby: getSortBy(path), - dircounts: getDirCounts(path), - dirfirst: getDirFirst(path), - dironly: getDirOnly(path), - hidden: getHidden(path), - reverse: getReverse(path), - visualAnchor: -1, - hiddenfiles: gOpts.hiddenfiles, - ignorecase: gOpts.ignorecase, - ignoredia: gOpts.ignoredia, + loading: true, + loadTime: time.Now(), + path: path, + sortby: getSortBy(path), + dircounts: getDirCounts(path), + dirfirst: getDirFirst(path), + dironly: getDirOnly(path), + hidden: getHidden(path), + reverse: getReverse(path), + visualAnchor: -1, + hiddenfiles: gOpts.hiddenfiles, + sortignorecase: getSortIgnoreCase(path), + sortignoredia: getSortIgnoreDia(path), } nav.dirCache[path] = d return d @@ -546,8 +546,8 @@ func (nav *nav) checkDir(dir *dir) { dir.hidden != getHidden(dir.path) || dir.reverse != getReverse(dir.path) || !slices.Equal(dir.hiddenfiles, gOpts.hiddenfiles) || - dir.ignorecase != gOpts.ignorecase || - dir.ignoredia != gOpts.ignoredia: + dir.sortignorecase != getSortIgnoreCase(dir.path) || + dir.sortignoredia != getSortIgnoreDia(dir.path): dir.loading = true sd := *dir go func() { diff --git a/opts.go b/opts.go index 3140253b..afcee68f 100644 --- a/opts.go +++ b/opts.go @@ -144,6 +144,8 @@ var gOpts struct { smartcase bool smartdia bool sortby sortMethod + sortignorecase bool + sortignoredia bool statfmt string tabstop int tagfmt string @@ -165,13 +167,15 @@ var gOpts struct { } var gLocalOpts struct { - dircounts map[string]bool - dirfirst map[string]bool - dironly map[string]bool - hidden map[string]bool - info map[string][]string - reverse map[string]bool - sortby map[string]sortMethod + dircounts map[string]bool + dirfirst map[string]bool + dironly map[string]bool + hidden map[string]bool + info map[string][]string + reverse map[string]bool + sortby map[string]sortMethod + sortignorecase map[string]bool + sortignoredia map[string]bool } func getDirCounts(path string) bool { @@ -223,6 +227,20 @@ func getSortBy(path string) sortMethod { return gOpts.sortby } +func getSortIgnoreCase(path string) bool { + if val, ok := gLocalOpts.sortignorecase[path]; ok { + return val + } + return gOpts.sortignorecase +} + +func getSortIgnoreDia(path string) bool { + if val, ok := gLocalOpts.sortignoredia[path]; ok { + return val + } + return gOpts.sortignoredia +} + func init() { gOpts.anchorfind = true gOpts.autoquit = true @@ -287,6 +305,8 @@ func init() { gOpts.smartcase = true gOpts.smartdia = false gOpts.sortby = naturalSort + gOpts.sortignorecase = true + gOpts.sortignoredia = true gOpts.statfmt = "\033[36m%p\033[0m| %c| %u| %g| %S| %t| -> %l" gOpts.tabstop = 8 gOpts.tagfmt = "\033[31m" @@ -438,6 +458,8 @@ func init() { gLocalOpts.info = make(map[string][]string) gLocalOpts.reverse = make(map[string]bool) gLocalOpts.sortby = make(map[string]sortMethod) + gLocalOpts.sortignorecase = make(map[string]bool) + gLocalOpts.sortignoredia = make(map[string]bool) setDefaults() }