diff --git a/doc.go b/doc.go index 50868ada..de0d7536 100644 --- a/doc.go +++ b/doc.go @@ -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: diff --git a/docstring.go b/docstring.go index e108cad8..a2322bb3 100644 --- a/docstring.go +++ b/docstring.go @@ -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 diff --git a/eval.go b/eval.go index 71bccbc4..07bab874 100644 --- a/eval.go +++ b/eval.go @@ -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) diff --git a/lf.1 b/lf.1 index 9e288ae8..08dfde48 100644 --- a/lf.1 +++ b/lf.1 @@ -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 diff --git a/main.go b/main.go index 99a87a94..301e8b4f 100644 --- a/main.go +++ b/main.go @@ -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) diff --git a/opts.go b/opts.go index cd2f890b..55a2f7be 100644 --- a/opts.go +++ b/opts.go @@ -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[""] = &callExpr{"cmd-transpose-word", nil, 1} gOpts.cmds = make(map[string]expr) + gOpts.user = make(map[string]string) setDefaults() }