diff --git a/doc.go b/doc.go index 1704fcb3..300c6891 100644 --- a/doc.go +++ b/doc.go @@ -157,6 +157,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: @@ -172,6 +173,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: @@ -795,6 +797,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 c5c538b8..6d580a05 100644 --- a/docstring.go +++ b/docstring.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: @@ -848,6 +850,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 53191b46..a47d5ad9 100644 --- a/eval.go +++ b/eval.go @@ -432,7 +432,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 f0a7311c..5dc7dc37 100644 --- a/lf.1 +++ b/lf.1 @@ -176,6 +176,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: @@ -193,6 +194,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: @@ -969,6 +971,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 2909809f..d0d700dd 100644 --- a/opts.go +++ b/opts.go @@ -72,6 +72,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 @@ -231,6 +232,7 @@ func init() { gOpts.cmdkeys[""] = &callExpr{"cmd-transpose-word", nil, 1} gOpts.cmds = make(map[string]expr) + gOpts.user = make(map[string]string) setDefaults() }