add user defined options (#865)

This commit is contained in:
Christian Zangl authored and GitHub committed 2022-10-15 15:50:21 +03:00
1 parent 62621736b3
commit a2fed6d16e
6 files changed
+36 -1

No files matched your search

+6
View File
@@ -161,6 +161,7 @@ The following options can be used to customize the behavior of lf:
waitmsg string (default 'Press any key to continue')
wrapscan bool (default on)
wrapscroll bool (default off)
user_{key} string (default none)
The following environment variables are exported for shell commands:
@@ -176,6 +177,7 @@ The following environment variables are exported for shell commands:
PAGER
SHELL
lf_{option}
lf_user_{key}
The following special shell commands are used to customize the behavior of lf when defined:
@@ -817,6 +819,10 @@ Searching can wrap around the file list.
Scrolling can wrap around the file list.
user_{key} string (default none)
Any option that is prefixed with 'user_' is a user defined option and can be set to any string. Inside a user defined command the value will be provided in the `lf_user_{key}` environment variable. These options are not used by lf and are not persisted.
Environment Variables
The following variables are exported for shell commands:
+9
View File
@@ -164,6 +164,7 @@ The following options can be used to customize the behavior of lf:
waitmsg string (default 'Press any key to continue')
wrapscan bool (default on)
wrapscroll bool (default off)
user_{key} string (default none)
The following environment variables are exported for shell commands:
@@ -179,6 +180,7 @@ The following environment variables are exported for shell commands:
PAGER
SHELL
lf_{option}
lf_user_{key}
The following special shell commands are used to customize the behavior of
lf when defined:
@@ -867,6 +869,13 @@ Searching can wrap around the file list.
Scrolling can wrap around the file list.
user_{key} string (default none)
Any option that is prefixed with 'user_' is a user defined option and can be
set to any string. Inside a user defined command the value will be provided
in the 'lf_user_{key}' environment variable. These options are not used by
lf and are not persisted.
Environment Variables
+6 -1
View File
@@ -442,7 +442,12 @@ func (e *setExpr) eval(app *app, args []string) {
gOpts.truncatechar = e.val
default:
app.ui.echoerrf("unknown option: %s", e.opt)
// any key with the prefix user_ is accepted as a user defined option
if strings.HasPrefix(e.opt, "user_") {
gOpts.user[e.opt[5:]] = e.val
} else {
app.ui.echoerrf("unknown option: %s", e.opt)
}
return
}
app.ui.loadFileInfo(app.nav)
+8
View File
@@ -179,6 +179,7 @@ The following options can be used to customize the behavior of lf:
waitmsg string (default 'Press any key to continue')
wrapscan bool (default on)
wrapscroll bool (default off)
user_{key} string (default none)
.EE
.PP
The following environment variables are exported for shell commands:
@@ -196,6 +197,7 @@ The following environment variables are exported for shell commands:
PAGER
SHELL
lf_{option}
lf_user_{key}
.EE
.PP
The following special shell commands are used to customize the behavior of lf when defined:
@@ -990,6 +992,12 @@ Searching can wrap around the file list.
.EE
.PP
Scrolling can wrap around the file list.
.PP
.EX
user_{key} string (default none)
.EE
.PP
Any option that is prefixed with 'user_' is a user defined option and can be set to any string. Inside a user defined command the value will be provided in the `lf_user_{key}` environment variable. These options are not used by lf and are not persisted.
.SH ENVIRONMENT VARIABLES
The following variables are exported for shell commands: These are referred with a '$' prefix on POSIX shells (e.g. '$f'), between '%' characters on Windows cmd (e.g. '%f%'), and with a '$env:' prefix on Windows powershell (e.g. '$env:f').
.PP
+5
View File
@@ -152,6 +152,11 @@ func exportOpts() {
dirfirst := strconv.FormatBool(gOpts.sortType.option&dirfirstSort != 0)
os.Setenv("lf_dirfirst", dirfirst)
} else if name == "lf_user" {
// set each user option
for key, value := range gOpts.user {
os.Setenv(name+"_"+key, value)
}
} else {
field := e.Field(i)
value := fieldToString(field)
+2
View File
@@ -75,6 +75,7 @@ var gOpts struct {
keys map[string]expr
cmdkeys map[string]expr
cmds map[string]expr
user map[string]string
sortType sortType
tempmarks string
tagfmt string
@@ -237,6 +238,7 @@ func init() {
gOpts.cmdkeys["<a-t>"] = &callExpr{"cmd-transpose-word", nil, 1}
gOpts.cmds = make(map[string]expr)
gOpts.user = make(map[string]string)
setDefaults()
}