diff --git a/app.go b/app.go index 2eb0b17a..58f73942 100644 --- a/app.go +++ b/app.go @@ -480,6 +480,7 @@ func (app *app) loop() { // & No Yes No No No Do nothing func (app *app) runShell(s string, args []string, prefix string) { app.nav.exportFiles() + app.ui.exportSizes() exportOpts() cmd := shellCommand(s, args) diff --git a/doc.go b/doc.go index 3ae7a7e8..91b7f635 100644 --- a/doc.go +++ b/doc.go @@ -161,7 +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) + user_{option} string (default none) The following environment variables are exported for shell commands: @@ -177,7 +177,9 @@ The following environment variables are exported for shell commands: PAGER SHELL lf_{option} - lf_user_{key} + lf_user_{option} + lf_width + lf_height The following special shell commands are used to customize the behavior of lf when defined: @@ -840,10 +842,10 @@ Searching can wrap around the file list. Scrolling can wrap around the file list. - user_{key} string (default none) + user_{option} 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. +Inside a user defined command the value will be provided in the `lf_user_{option}` environment variable. These options are not used by lf and are not persisted. # Environment Variables @@ -901,6 +903,15 @@ If this variable is set in the environment, use the same value, otherwise set th Value of the {option}. + lf_user_{option} + +Value of the user_{option}. + + lf_width + lf_height + +Width/Height of the terminal. + # Special Commands This section shows information about special shell commands. @@ -1204,12 +1215,10 @@ So now you can display a message in the current client by calling the following Since lf does not have control flow syntax, remote commands are used for such needs. For example, you can configure the number of columns in the ui with respect to the terminal width as follows: - cmd recol ${{ - # Use ${{ instead of %{{ to work around https://github.com/gokcehan/lf/issues/718. - w=$(tput cols) - if [ $w -le 80 ]; then + cmd recol %{{ + if [ $lf_width -le 80 ]; then lf -remote "send $id set ratios 1:2" - elif [ $w -le 160 ]; then + elif [ $lf_width -le 160 ]; then lf -remote "send $id set ratios 1:2:3" else lf -remote "send $id set ratios 1:2:3:5" diff --git a/docstring.go b/docstring.go index 90c13b53..fb77a29e 100644 --- a/docstring.go +++ b/docstring.go @@ -164,7 +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) + user_{option} string (default none) The following environment variables are exported for shell commands: @@ -180,7 +180,9 @@ The following environment variables are exported for shell commands: PAGER SHELL lf_{option} - lf_user_{key} + lf_user_{option} + lf_width + lf_height The following special shell commands are used to customize the behavior of lf when defined: @@ -887,12 +889,12 @@ Searching can wrap around the file list. Scrolling can wrap around the file list. - user_{key} string (default none) + user_{option} 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. +'lf_user_{option}' environment variable. These options are not used by lf and +are not persisted. # Environment Variables @@ -957,6 +959,15 @@ the value to 'sh' on Unix, 'cmd' in Windows. Value of the {option}. + lf_user_{option} + +Value of the user_{option}. + + lf_width + lf_height + +Width/Height of the terminal. + # Special Commands This section shows information about special shell commands. @@ -1286,12 +1297,10 @@ Since lf does not have control flow syntax, remote commands are used for such needs. For example, you can configure the number of columns in the ui with respect to the terminal width as follows: - cmd recol ${{ - # Use ${{ instead of %{{ to work around https://github.com/gokcehan/lf/issues/718. - w=$(tput cols) - if [ $w -le 80 ]; then + cmd recol %{{ + if [ $lf_width -le 80 ]; then lf -remote "send $id set ratios 1:2" - elif [ $w -le 160 ]; then + elif [ $lf_width -le 160 ]; then lf -remote "send $id set ratios 1:2:3" else lf -remote "send $id set ratios 1:2:3:5" diff --git a/lf.1 b/lf.1 index 798053b1..99a7a7b1 100644 --- a/lf.1 +++ b/lf.1 @@ -180,7 +180,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) + user_{option} string (default none) .EE .PP The following environment variables are exported for shell commands: @@ -198,7 +198,9 @@ The following environment variables are exported for shell commands: PAGER SHELL lf_{option} - lf_user_{key} + lf_user_{option} + lf_width + lf_height .EE .PP The following special shell commands are used to customize the behavior of lf when defined: @@ -1028,10 +1030,10 @@ Searching can wrap around the file list. Scrolling can wrap around the file list. .PP .EX - user_{key} string (default none) + user_{option} 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. +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_{option}` 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 @@ -1106,6 +1108,19 @@ If this variable is set in the environment, use the same value, otherwise set th .EE .PP Value of the {option}. +.PP +.EX + lf_user_{option} +.EE +.PP +Value of the user_{option}. +.PP +.EX + lf_width + lf_height +.EE +.PP +Width/Height of the terminal. .SH SPECIAL COMMANDS This section shows information about special shell commands. .PP @@ -1435,12 +1450,10 @@ All clients have a unique id number but you may not be aware of the id number wh Since lf does not have control flow syntax, remote commands are used for such needs. For example, you can configure the number of columns in the ui with respect to the terminal width as follows: .PP .EX - cmd recol ${{ - # Use ${{ instead of %{{ to work around https://github.com/gokcehan/lf/issues/718. - w=$(tput cols) - if [ $w -le 80 ]; then + cmd recol %{{ + if [ $lf_width -le 80 ]; then lf -remote "send $id set ratios 1:2" - elif [ $w -le 160 ]; then + elif [ $lf_width -le 160 ]; then lf -remote "send $id set ratios 1:2:3" else lf -remote "send $id set ratios 1:2:3:5" diff --git a/ui.go b/ui.go index f2c018a3..468141ee 100644 --- a/ui.go +++ b/ui.go @@ -1307,6 +1307,12 @@ func (ui *ui) resume() error { return err } +func (ui *ui) exportSizes() { + w, h := ui.screen.Size() + os.Setenv("lf_width", strconv.Itoa(w)) + os.Setenv("lf_height", strconv.Itoa(h)) +} + func anyKey() { fmt.Print(gOpts.waitmsg) defer fmt.Print("\n")