Sort options in alphabetical order (#2074)

* Sort options in alphabetical order

* Sort `eval.go` too
This commit is contained in:
Joe Lim authored and GitHub committed 2025-08-04 16:26:33 +10:00
1 parent 44483d7872
commit 47b3bc5617
5 files changed
+147 -147

No files matched your search

+15 -15
View File
@@ -838,14 +838,14 @@ Ignore case in sorting and search patterns.
Ignore diacritics in sorting and search patterns. Ignore diacritics in sorting and search patterns.
## incsearch (bool) (default false)
Jump to the first match after each keystroke during searching.
## incfilter (bool) (default false) ## incfilter (bool) (default false)
Apply filter pattern after each keystroke during filtering. Apply filter pattern after each keystroke during filtering.
## incsearch (bool) (default false)
Jump to the first match after each keystroke during searching.
## info ([]string) (default ``) ## info ([]string) (default ``)
A list of information that is shown for directory items at the right side of the pane. A list of information that is shown for directory items at the right side of the pane.
@@ -944,16 +944,6 @@ Additional expansions are provided for environment variables exported by lf, in
Expansions are also provided for user-defined options, in the form `%{lf_user_<name>}` (e.g. `%{lf_user_foo}`). Expansions are also provided for user-defined options, in the form `%{lf_user_<name>}` (e.g. `%{lf_user_foo}`).
The `|` character splits the format string into sections. Any section containing a failed expansion (result is a blank string) is discarded and not shown. The `|` character splits the format string into sections. Any section containing a failed expansion (result is a blank string) is discarded and not shown.
## selectfmt (string) (default `\033[7;35m`)
Format string of the indicator for files that are selected.
## selmode (string) (default `all`)
Selection mode for commands.
When set to `all` it will use the selected files from all directories.
When set to `dir` it will only use the selected files in the current directory.
## scrolloff (int) (default 0) ## scrolloff (int) (default 0)
Minimum number of offset lines shown at all times at the top and bottom of the screen when scrolling. Minimum number of offset lines shown at all times at the top and bottom of the screen when scrolling.
@@ -966,6 +956,16 @@ How search command patterns are treated.
Currently supported methods are `text` (i.e. string literals), `glob` (i.e shell globs) and `regex` (i.e. regular expressions). Currently supported methods are `text` (i.e. string literals), `glob` (i.e shell globs) and `regex` (i.e. regular expressions).
See `SEARCHING FILES` for more details. See `SEARCHING FILES` for more details.
## selectfmt (string) (default `\033[7;35m`)
Format string of the indicator for files that are selected.
## selmode (string) (default `all`)
Selection mode for commands.
When set to `all` it will use the selected files from all directories.
When set to `dir` it will only use the selected files in the current directory.
## shell (string) (default `sh` for Unix and `cmd` for Windows) ## shell (string) (default `sh` for Unix and `cmd` for Windows)
Shell executable to use for shell commands. Shell executable to use for shell commands.
@@ -1267,7 +1267,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) 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. 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`, `sortby` and `locale`. Currently supported local options are `dircounts`, `dirfirst`, `dironly`, `hidden`, `info`, `locale`, `reverse` and `sortby`.
Adding a trailing path separator (i.e. `/` for Unix and `\` for Windows) sets the option for the given directory along with its subdirectories: Adding a trailing path separator (i.e. `/` for Unix and `\` for Windows) sets the option for the given directory along with its subdirectories:
setlocal /foo/bar hidden # boolean enable setlocal /foo/bar hidden # boolean enable
+15 -15
View File
@@ -890,14 +890,14 @@ ignoredia (bool) (default true)
Ignore diacritics in sorting and search patterns. Ignore diacritics in sorting and search patterns.
incsearch (bool) (default false)
Jump to the first match after each keystroke during searching.
incfilter (bool) (default false) incfilter (bool) (default false)
Apply filter pattern after each keystroke during filtering. Apply filter pattern after each keystroke during filtering.
incsearch (bool) (default false)
Jump to the first match after each keystroke during searching.
info ([]string) (default ``) info ([]string) (default ``)
A list of information that is shown for directory items at the right A list of information that is shown for directory items at the right
@@ -1027,16 +1027,6 @@ for user-defined options, in the form %{lf_user_<name>} (e.g.
Any section containing a failed expansion (result is a blank string) is Any section containing a failed expansion (result is a blank string) is
discarded and not shown. discarded and not shown.
selectfmt (string) (default \033[7;35m)
Format string of the indicator for files that are selected.
selmode (string) (default all)
Selection mode for commands. When set to all it will use the selected
files from all directories. When set to dir it will only use the
selected files in the current directory.
scrolloff (int) (default 0) scrolloff (int) (default 0)
Minimum number of offset lines shown at all times at the top and bottom Minimum number of offset lines shown at all times at the top and bottom
@@ -1052,6 +1042,16 @@ How search command patterns are treated. Currently supported methods are
text (i.e. string literals), glob (i.e shell globs) and regex (i.e. text (i.e. string literals), glob (i.e shell globs) and regex (i.e.
regular expressions). See SEARCHING FILES for more details. regular expressions). See SEARCHING FILES for more details.
selectfmt (string) (default \033[7;35m)
Format string of the indicator for files that are selected.
selmode (string) (default all)
Selection mode for commands. When set to all it will use the selected
files from all directories. When set to dir it will only use the
selected files in the current directory.
shell (string) (default sh for Unix and cmd for Windows) shell (string) (default sh for Unix and cmd for Windows)
Shell executable to use for shell commands. Shell commands are executed Shell executable to use for shell commands. Shell commands are executed
@@ -1398,7 +1398,7 @@ string:
Command setlocal is used to set a local option for a directory which can 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, be a boolean or string. Currently supported local options are dircounts,
dirfirst, dironly, hidden, info, reverse, sortby and locale. Adding a dirfirst, dironly, hidden, info, locale, reverse and sortby. Adding a
trailing path separator (i.e. / for Unix and \ for Windows) sets the trailing path separator (i.e. / for Unix and \ for Windows) sets the
option for the given directory along with its subdirectories: option for the given directory along with its subdirectories:
+21 -21
View File
@@ -287,6 +287,10 @@ func (e *setExpr) eval(app *app, args []string) {
} }
} }
gOpts.info = toks gOpts.info = toks
case "infotimefmtnew":
gOpts.infotimefmtnew = e.val
case "infotimefmtold":
gOpts.infotimefmtold = e.val
case "locale": case "locale":
localeStr := e.val localeStr := e.val
if localeStr != localeStrDisable { if localeStr != localeStrDisable {
@@ -298,27 +302,6 @@ func (e *setExpr) eval(app *app, args []string) {
gOpts.locale = localeStr gOpts.locale = localeStr
app.nav.sort() app.nav.sort()
app.ui.sort() app.ui.sort()
case "rulerfmt":
gOpts.rulerfmt = e.val
case "preserve":
if e.val == "" {
gOpts.preserve = nil
return
}
toks := strings.Split(e.val, ":")
for _, s := range toks {
switch s {
case "mode", "timestamps":
default:
app.ui.echoerr("preserve: should consist of 'mode' or 'timestamps' separated with colon")
return
}
}
gOpts.preserve = toks
case "infotimefmtnew":
gOpts.infotimefmtnew = e.val
case "infotimefmtold":
gOpts.infotimefmtold = e.val
case "numberfmt": case "numberfmt":
gOpts.numberfmt = e.val gOpts.numberfmt = e.val
case "period": case "period":
@@ -338,6 +321,21 @@ func (e *setExpr) eval(app *app, args []string) {
app.ticker.Stop() app.ticker.Stop()
app.ticker = time.NewTicker(time.Duration(gOpts.period) * time.Second) app.ticker = time.NewTicker(time.Duration(gOpts.period) * time.Second)
} }
case "preserve":
if e.val == "" {
gOpts.preserve = nil
return
}
toks := strings.Split(e.val, ":")
for _, s := range toks {
switch s {
case "mode", "timestamps":
default:
app.ui.echoerr("preserve: should consist of 'mode' or 'timestamps' separated with colon")
return
}
}
gOpts.preserve = toks
case "previewer": case "previewer":
gOpts.previewer = replaceTilde(e.val) gOpts.previewer = replaceTilde(e.val)
case "promptfmt": case "promptfmt":
@@ -367,6 +365,8 @@ func (e *setExpr) eval(app *app, args []string) {
clear(app.nav.regCache) clear(app.nav.regCache)
} }
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
case "rulerfmt":
gOpts.rulerfmt = e.val
case "scrolloff": case "scrolloff":
n, err := strconv.Atoi(e.val) n, err := strconv.Atoi(e.val)
if err != nil { if err != nil {
+13 -13
View File
@@ -1,6 +1,6 @@
.\" Automatically generated by Pandoc 3.7.0.2 .\" Automatically generated by Pandoc 3.7.0.2
.\" .\"
.TH "LF" "1" "2025\-07\-26" "r37" "DOCUMENTATION" .TH "LF" "1" "2025\-08\-04" "r37" "DOCUMENTATION"
.SH NAME .SH NAME
lf \- terminal file manager lf \- terminal file manager
.SH SYNOPSIS .SH SYNOPSIS
@@ -781,10 +781,10 @@ This option does not have any effect on Windows.
Ignore case in sorting and search patterns. Ignore case in sorting and search patterns.
.SS ignoredia (bool) (default true) .SS ignoredia (bool) (default true)
Ignore diacritics in sorting and search patterns. Ignore diacritics in sorting and search patterns.
.SS incsearch (bool) (default false)
Jump to the first match after each keystroke during searching.
.SS incfilter (bool) (default false) .SS incfilter (bool) (default false)
Apply filter pattern after each keystroke during filtering. Apply filter pattern after each keystroke during filtering.
.SS incsearch (bool) (default false)
Jump to the first match after each keystroke during searching.
.SS info ([]string) (default \(ga\(ga) .SS info ([]string) (default \(ga\(ga)
A list of information that is shown for directory items at the right A list of information that is shown for directory items at the right
side of the pane. side of the pane.
@@ -904,14 +904,6 @@ Expansions are also provided for user\-defined options, in the form
The \f[CR]|\f[R] character splits the format string into sections. The \f[CR]|\f[R] character splits the format string into sections.
Any section containing a failed expansion (result is a blank string) is Any section containing a failed expansion (result is a blank string) is
discarded and not shown. discarded and not shown.
.SS selectfmt (string) (default \f[CR]\(rs033[7;35m\f[R])
Format string of the indicator for files that are selected.
.SS selmode (string) (default \f[CR]all\f[R])
Selection mode for commands.
When set to \f[CR]all\f[R] it will use the selected files from all
directories.
When set to \f[CR]dir\f[R] it will only use the selected files in the
current directory.
.SS scrolloff (int) (default 0) .SS scrolloff (int) (default 0)
Minimum number of offset lines shown at all times at the top and bottom Minimum number of offset lines shown at all times at the top and bottom
of the screen when scrolling. of the screen when scrolling.
@@ -926,6 +918,14 @@ string literals), \f[CR]glob\f[R] (i.e shell globs) and \f[CR]regex\f[R]
(i.e. (i.e.
regular expressions). regular expressions).
See \f[CR]SEARCHING FILES\f[R] for more details. See \f[CR]SEARCHING FILES\f[R] for more details.
.SS selectfmt (string) (default \f[CR]\(rs033[7;35m\f[R])
Format string of the indicator for files that are selected.
.SS selmode (string) (default \f[CR]all\f[R])
Selection mode for commands.
When set to \f[CR]all\f[R] it will use the selected files from all
directories.
When set to \f[CR]dir\f[R] it will only use the selected files in the
current directory.
.SS shell (string) (default \f[CR]sh\f[R] for Unix and \f[CR]cmd\f[R] for Windows) .SS shell (string) (default \f[CR]sh\f[R] for Unix and \f[CR]cmd\f[R] for Windows)
Shell executable to use for shell commands. Shell executable to use for shell commands.
Shell commands are executed as Shell commands are executed as
@@ -1205,8 +1205,8 @@ Command \f[CR]setlocal\f[R] is used to set a local option for a
directory which can be a boolean or string. directory which can be a boolean or string.
Currently supported local options are \f[CR]dircounts\f[R], Currently supported local options are \f[CR]dircounts\f[R],
\f[CR]dirfirst\f[R], \f[CR]dironly\f[R], \f[CR]hidden\f[R], \f[CR]dirfirst\f[R], \f[CR]dironly\f[R], \f[CR]hidden\f[R],
\f[CR]info\f[R], \f[CR]reverse\f[R], \f[CR]sortby\f[R] and \f[CR]info\f[R], \f[CR]locale\f[R], \f[CR]reverse\f[R] and
\f[CR]locale\f[R]. \f[CR]sortby\f[R].
Adding a trailing path separator (i.e. Adding a trailing path separator (i.e.
\f[CR]/\f[R] for Unix and \f[CR]\(rs\f[R] for Windows) sets the option \f[CR]/\f[R] for Unix and \f[CR]\(rs\f[R] for Windows) sets the option
for the given directory along with its subdirectories: for the given directory along with its subdirectories:
+83 -83
View File
@@ -47,6 +47,7 @@ var gOpts struct {
anchorfind bool anchorfind bool
autoquit bool autoquit bool
borderfmt string borderfmt string
cleaner string
copyfmt string copyfmt string
cursoractivefmt string cursoractivefmt string
cursorparentfmt string cursorparentfmt string
@@ -59,77 +60,76 @@ var gOpts struct {
dirpreviews bool dirpreviews bool
drawbox bool drawbox bool
dupfilefmt string dupfilefmt string
searchmethod searchMethod errorfmt string
filesep string
filtermethod searchMethod filtermethod searchMethod
findlen int
hidden bool hidden bool
hiddenfiles []string
history bool
icons bool icons bool
ifs string
ignorecase bool ignorecase bool
ignoredia bool ignoredia bool
incfilter bool incfilter bool
incsearch bool incsearch bool
info []string
infotimefmtnew string
infotimefmtold string
locale string locale string
mouse bool mouse bool
number bool number bool
numberfmt string
period int
preserve []string
preview bool preview bool
previewer string
promptfmt string
ratios []int
relativenumber bool relativenumber bool
reverse bool reverse bool
roundbox bool roundbox bool
rulerfmt string
scrolloff int
searchmethod searchMethod
selectfmt string selectfmt string
visualfmt string selmode string
shell string
shellflag string
shellopts []string
showbinds bool showbinds bool
sixel bool sixel bool
sortby sortMethod
smartcase bool smartcase bool
smartdia bool smartdia bool
sortby sortMethod
statfmt string
tabstop int
tagfmt string
tempmarks string
timefmt string
truncatechar string
truncatepct int
visualfmt string
waitmsg string waitmsg string
watch bool watch bool
wrapscan bool wrapscan bool
wrapscroll bool wrapscroll bool
findlen int
period int
scrolloff int
tabstop int
errorfmt string
filesep string
ifs string
previewer string
cleaner string
promptfmt string
selmode string
shell string
shellflag string
statfmt string
timefmt string
infotimefmtnew string
infotimefmtold string
truncatechar string
truncatepct int
ratios []int
hiddenfiles []string
history bool
info []string
rulerfmt string
preserve []string
shellopts []string
nkeys map[string]expr nkeys map[string]expr
vkeys map[string]expr vkeys map[string]expr
cmdkeys map[string]expr cmdkeys map[string]expr
cmds map[string]expr cmds map[string]expr
user map[string]string user map[string]string
tempmarks string
numberfmt string
tagfmt string
} }
var gLocalOpts struct { var gLocalOpts struct {
sortby map[string]sortMethod
dircounts map[string]bool dircounts map[string]bool
dirfirst map[string]bool dirfirst map[string]bool
dironly map[string]bool dironly map[string]bool
hidden map[string]bool hidden map[string]bool
reverse map[string]bool
info map[string][]string info map[string][]string
locale map[string]string locale map[string]string
reverse map[string]bool
sortby map[string]sortMethod
} }
func localOptPaths(path string) []string { func localOptPaths(path string) []string {
@@ -185,6 +185,15 @@ func getInfo(path string) []string {
return gOpts.info return gOpts.info
} }
func getLocale(path string) string {
for _, key := range localOptPaths(path) {
if val, ok := gLocalOpts.locale[key]; ok {
return val
}
}
return gOpts.locale
}
func getReverse(path string) bool { func getReverse(path string) bool {
for _, key := range localOptPaths(path) { for _, key := range localOptPaths(path) {
if val, ok := gLocalOpts.reverse[key]; ok { if val, ok := gLocalOpts.reverse[key]; ok {
@@ -203,18 +212,16 @@ func getSortBy(path string) sortMethod {
return gOpts.sortby return gOpts.sortby
} }
func getLocale(path string) string {
for _, key := range localOptPaths(path) {
if val, ok := gLocalOpts.locale[key]; ok {
return val
}
}
return gOpts.locale
}
func init() { func init() {
gOpts.anchorfind = true gOpts.anchorfind = true
gOpts.autoquit = true gOpts.autoquit = true
gOpts.borderfmt = "\033[0m"
gOpts.cleaner = ""
gOpts.copyfmt = "\033[7;33m"
gOpts.cursoractivefmt = "\033[7m"
gOpts.cursorparentfmt = "\033[7m"
gOpts.cursorpreviewfmt = "\033[4m"
gOpts.cutfmt = "\033[7;31m"
gOpts.dircache = true gOpts.dircache = true
gOpts.dircounts = false gOpts.dircounts = false
gOpts.dirfirst = true gOpts.dirfirst = true
@@ -222,67 +229,60 @@ func init() {
gOpts.dirpreviews = false gOpts.dirpreviews = false
gOpts.drawbox = false gOpts.drawbox = false
gOpts.dupfilefmt = "%f.~%n~" gOpts.dupfilefmt = "%f.~%n~"
gOpts.borderfmt = "\033[0m" gOpts.errorfmt = "\033[7;31;47m"
gOpts.copyfmt = "\033[7;33m" gOpts.filesep = "\n"
gOpts.cursoractivefmt = "\033[7m"
gOpts.cursorparentfmt = "\033[7m"
gOpts.cursorpreviewfmt = "\033[4m"
gOpts.cutfmt = "\033[7;31m"
gOpts.filtermethod = textSearch gOpts.filtermethod = textSearch
gOpts.searchmethod = textSearch gOpts.findlen = 1
gOpts.hidden = false gOpts.hidden = false
gOpts.hiddenfiles = gDefaultHiddenFiles
gOpts.history = true
gOpts.icons = false gOpts.icons = false
gOpts.ifs = ""
gOpts.ignorecase = true gOpts.ignorecase = true
gOpts.ignoredia = true gOpts.ignoredia = true
gOpts.incfilter = false gOpts.incfilter = false
gOpts.incsearch = false gOpts.incsearch = false
gOpts.info = nil
gOpts.infotimefmtnew = "Jan _2 15:04"
gOpts.infotimefmtold = "Jan _2 2006"
gOpts.locale = localeStrDisable gOpts.locale = localeStrDisable
gOpts.mouse = false gOpts.mouse = false
gOpts.number = false gOpts.number = false
gOpts.numberfmt = "\033[33m"
gOpts.period = 0
gOpts.preserve = []string{"mode"}
gOpts.preview = true gOpts.preview = true
gOpts.previewer = ""
gOpts.promptfmt = "\033[32;1m%u@%h\033[0m:\033[34;1m%d\033[0m\033[1m%f\033[0m"
gOpts.ratios = []int{1, 2, 3}
gOpts.relativenumber = false gOpts.relativenumber = false
gOpts.reverse = false gOpts.reverse = false
gOpts.roundbox = false gOpts.roundbox = false
gOpts.rulerfmt = " %a| %p| \033[7;31m %m \033[0m| \033[7;33m %c \033[0m| \033[7;35m %s \033[0m| \033[7;36m %v \033[0m| \033[7;34m %f \033[0m| %i/%t"
gOpts.scrolloff = 0
gOpts.searchmethod = textSearch
gOpts.selectfmt = "\033[7;35m" gOpts.selectfmt = "\033[7;35m"
gOpts.visualfmt = "\033[7;36m" gOpts.selmode = "all"
gOpts.shell = gDefaultShell
gOpts.shellflag = gDefaultShellFlag
gOpts.shellopts = nil
gOpts.showbinds = true gOpts.showbinds = true
gOpts.sixel = false gOpts.sixel = false
gOpts.sortby = naturalSort
gOpts.smartcase = true gOpts.smartcase = true
gOpts.smartdia = false gOpts.smartdia = false
gOpts.sortby = naturalSort
gOpts.statfmt = "\033[36m%p\033[0m| %c| %u| %g| %S| %t| -> %l"
gOpts.tabstop = 8
gOpts.tagfmt = "\033[31m"
gOpts.tempmarks = "'"
gOpts.timefmt = time.ANSIC
gOpts.truncatechar = "~"
gOpts.truncatepct = 100
gOpts.visualfmt = "\033[7;36m"
gOpts.waitmsg = "Press any key to continue" gOpts.waitmsg = "Press any key to continue"
gOpts.watch = false gOpts.watch = false
gOpts.wrapscan = true gOpts.wrapscan = true
gOpts.wrapscroll = false gOpts.wrapscroll = false
gOpts.findlen = 1
gOpts.period = 0
gOpts.scrolloff = 0
gOpts.tabstop = 8
gOpts.errorfmt = "\033[7;31;47m"
gOpts.filesep = "\n"
gOpts.ifs = ""
gOpts.previewer = ""
gOpts.cleaner = ""
gOpts.promptfmt = "\033[32;1m%u@%h\033[0m:\033[34;1m%d\033[0m\033[1m%f\033[0m"
gOpts.selmode = "all"
gOpts.shell = gDefaultShell
gOpts.shellflag = gDefaultShellFlag
gOpts.statfmt = "\033[36m%p\033[0m| %c| %u| %g| %S| %t| -> %l"
gOpts.timefmt = time.ANSIC
gOpts.infotimefmtnew = "Jan _2 15:04"
gOpts.infotimefmtold = "Jan _2 2006"
gOpts.truncatechar = "~"
gOpts.truncatepct = 100
gOpts.ratios = []int{1, 2, 3}
gOpts.hiddenfiles = gDefaultHiddenFiles
gOpts.history = true
gOpts.info = nil
gOpts.rulerfmt = " %a| %p| \033[7;31m %m \033[0m| \033[7;33m %c \033[0m| \033[7;35m %s \033[0m| \033[7;36m %v \033[0m| \033[7;34m %f \033[0m| %i/%t"
gOpts.preserve = []string{"mode"}
gOpts.shellopts = nil
gOpts.tempmarks = "'"
gOpts.numberfmt = "\033[33m"
gOpts.tagfmt = "\033[31m"
// Normal and Visual mode // Normal and Visual mode
keys := map[string]expr{ keys := map[string]expr{
@@ -416,14 +416,14 @@ func init() {
gOpts.cmds = make(map[string]expr) gOpts.cmds = make(map[string]expr)
gOpts.user = make(map[string]string) gOpts.user = make(map[string]string)
gLocalOpts.sortby = make(map[string]sortMethod)
gLocalOpts.dircounts = make(map[string]bool) gLocalOpts.dircounts = make(map[string]bool)
gLocalOpts.dirfirst = make(map[string]bool) gLocalOpts.dirfirst = make(map[string]bool)
gLocalOpts.dironly = make(map[string]bool) gLocalOpts.dironly = make(map[string]bool)
gLocalOpts.hidden = make(map[string]bool) gLocalOpts.hidden = make(map[string]bool)
gLocalOpts.reverse = make(map[string]bool)
gLocalOpts.info = make(map[string][]string) gLocalOpts.info = make(map[string][]string)
gLocalOpts.locale = make(map[string]string) gLocalOpts.locale = make(map[string]string)
gLocalOpts.reverse = make(map[string]bool)
gLocalOpts.sortby = make(map[string]sortMethod)
setDefaults() setDefaults()
} }