Make the :doc command work even if lf is not in the PATH, add lf environment variable (#1176)
* Export a `$lf` environment variable with path to lf binary If Go fails to find a path to the lf binary, `$lf` is set to the string `lf` so that running `$lf` in scripts gives a reasonable error message. * Make the `:doc` command work even if lf is not in the PATH Previously, `:doc` executed `lf -doc`. Now, it executed `$lf -doc` or `%lf% -doc`. Before this change, `:doc` did not work if `lf` is not in the PATH. This is likely to happen to new users who are trying out `lf` and need docs the most. Moreover, if you made some changes to the docs and ran `lf` with `go run .`, `:doc` would return the docs for the version of `lf` in the PATH instead of what is expected.
This commit is contained in:
1 parent
3ae67fc361
commit
27ab67aab7
6 files changed
+40
-18
No files matched your search
@@ -933,19 +933,23 @@ For example, with POSIX shells, you can use '[ -n "$LF_LEVEL" ] && PS1="$PS1""(l
|
||||
|
||||
OPENER
|
||||
|
||||
If this variable is set in the environment, use the same value, otherwise set the value to 'start' in Windows, 'open' in MacOS, 'xdg-open' in others.
|
||||
If this variable is set in the environment, use the same value. Otherwise, this is set to 'start' in Windows, 'open' in MacOS, 'xdg-open' in others.
|
||||
|
||||
EDITOR
|
||||
|
||||
If this variable is set in the environment, use the same value, otherwise set the value to 'vi' on Unix, 'notepad' in Windows.
|
||||
If this variable is set in the environment, use the same value. Otherwise, this is set to 'vi' on Unix, 'notepad' in Windows.
|
||||
|
||||
PAGER
|
||||
|
||||
If this variable is set in the environment, use the same value, otherwise set the value to 'less' on Unix, 'more' in Windows.
|
||||
If this variable is set in the environment, use the same value. Otherwise, this is set to 'less' on Unix, 'more' in Windows.
|
||||
|
||||
SHELL
|
||||
|
||||
If this variable is set in the environment, use the same value, otherwise set the value to 'sh' on Unix, 'cmd' in Windows.
|
||||
If this variable is set in the environment, use the same value. Otherwise, this is set to 'sh' on Unix, 'cmd' in Windows.
|
||||
|
||||
lf
|
||||
|
||||
Absolute path to the currently running lf binary, if it can be found. Otherwise, this is set to the string 'lf'.
|
||||
|
||||
lf_{option}
|
||||
|
||||
|
||||
+13
-8
@@ -996,23 +996,28 @@ $LF_LEVEL) "' in your shell configuration file (e.g. '~/.bashrc').
|
||||
|
||||
OPENER
|
||||
|
||||
If this variable is set in the environment, use the same value, otherwise set
|
||||
the value to 'start' in Windows, 'open' in MacOS, 'xdg-open' in others.
|
||||
If this variable is set in the environment, use the same value. Otherwise,
|
||||
this is set to 'start' in Windows, 'open' in MacOS, 'xdg-open' in others.
|
||||
|
||||
EDITOR
|
||||
|
||||
If this variable is set in the environment, use the same value, otherwise set
|
||||
the value to 'vi' on Unix, 'notepad' in Windows.
|
||||
If this variable is set in the environment, use the same value. Otherwise,
|
||||
this is set to 'vi' on Unix, 'notepad' in Windows.
|
||||
|
||||
PAGER
|
||||
|
||||
If this variable is set in the environment, use the same value, otherwise set
|
||||
the value to 'less' on Unix, 'more' in Windows.
|
||||
If this variable is set in the environment, use the same value. Otherwise,
|
||||
this is set to 'less' on Unix, 'more' in Windows.
|
||||
|
||||
SHELL
|
||||
|
||||
If this variable is set in the environment, use the same value, otherwise set
|
||||
the value to 'sh' on Unix, 'cmd' in Windows.
|
||||
If this variable is set in the environment, use the same value. Otherwise,
|
||||
this is set to 'sh' on Unix, 'cmd' in Windows.
|
||||
|
||||
lf
|
||||
|
||||
Absolute path to the currently running lf binary, if it can be found. Otherwise,
|
||||
this is set to the string 'lf'.
|
||||
|
||||
lf_{option}
|
||||
|
||||
|
||||
@@ -1130,25 +1130,31 @@ The value of this variable is set to the current nesting level when you run lf f
|
||||
OPENER
|
||||
.EE
|
||||
.PP
|
||||
If this variable is set in the environment, use the same value, otherwise set the value to 'start' in Windows, 'open' in MacOS, 'xdg-open' in others.
|
||||
If this variable is set in the environment, use the same value. Otherwise, this is set to 'start' in Windows, 'open' in MacOS, 'xdg-open' in others.
|
||||
.PP
|
||||
.EX
|
||||
EDITOR
|
||||
.EE
|
||||
.PP
|
||||
If this variable is set in the environment, use the same value, otherwise set the value to 'vi' on Unix, 'notepad' in Windows.
|
||||
If this variable is set in the environment, use the same value. Otherwise, this is set to 'vi' on Unix, 'notepad' in Windows.
|
||||
.PP
|
||||
.EX
|
||||
PAGER
|
||||
.EE
|
||||
.PP
|
||||
If this variable is set in the environment, use the same value, otherwise set the value to 'less' on Unix, 'more' in Windows.
|
||||
If this variable is set in the environment, use the same value. Otherwise, this is set to 'less' on Unix, 'more' in Windows.
|
||||
.PP
|
||||
.EX
|
||||
SHELL
|
||||
.EE
|
||||
.PP
|
||||
If this variable is set in the environment, use the same value, otherwise set the value to 'sh' on Unix, 'cmd' in Windows.
|
||||
If this variable is set in the environment, use the same value. Otherwise, this is set to 'sh' on Unix, 'cmd' in Windows.
|
||||
.PP
|
||||
.EX
|
||||
lf
|
||||
.EE
|
||||
.PP
|
||||
Absolute path to the currently running lf binary, if it can be found. Otherwise, this is set to the string 'lf'.
|
||||
.PP
|
||||
.EX
|
||||
lf_{option}
|
||||
|
||||
@@ -79,6 +79,13 @@ func exportEnvVars() {
|
||||
level++
|
||||
|
||||
os.Setenv("LF_LEVEL", strconv.Itoa(level))
|
||||
|
||||
lfPath, err := os.Executable()
|
||||
if err != nil {
|
||||
log.Printf("getting path to lf binary: %s", err)
|
||||
lfPath = "lf"
|
||||
}
|
||||
os.Setenv("lf", lfPath)
|
||||
}
|
||||
|
||||
// used by exportOpts below
|
||||
|
||||
@@ -159,7 +159,7 @@ func setDefaults() {
|
||||
gOpts.keys["i"] = &execExpr{"$", `$PAGER "$f"`}
|
||||
gOpts.keys["w"] = &execExpr{"$", "$SHELL"}
|
||||
|
||||
gOpts.cmds["doc"] = &execExpr{"$", "lf -doc | $PAGER"}
|
||||
gOpts.cmds["doc"] = &execExpr{"$", `"$lf" -doc | $PAGER`}
|
||||
gOpts.keys["<f-1>"] = &callExpr{"doc", nil, 1}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -115,7 +115,7 @@ func setDefaults() {
|
||||
gOpts.keys["i"] = &execExpr{"!", "%PAGER% %f%"}
|
||||
gOpts.keys["w"] = &execExpr{"$", "%SHELL%"}
|
||||
|
||||
gOpts.cmds["doc"] = &execExpr{"!", "lf -doc | %PAGER%"}
|
||||
gOpts.cmds["doc"] = &execExpr{"!", "%lf% -doc | %PAGER%"}
|
||||
gOpts.keys["<f-1>"] = &callExpr{"doc", nil, 1}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user