Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the :doc command work even if lf is not in the PATH, add lf environment variable #1176

Merged
merged 2 commits into from
Apr 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -927,19 +927,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}

Expand Down
21 changes: 13 additions & 8 deletions docstring.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions lf.1
Original file line number Diff line number Diff line change
Expand Up @@ -1122,25 +1122,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}
Expand Down
7 changes: 7 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion os.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}

Expand Down
2 changes: 1 addition & 1 deletion os_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}

Expand Down