mirror of
https://github.com/junegunn/fzf.git
synced 2025-08-02 21:22:01 -07:00
Embed man page in the binary and show it on 'fzf --man'
This commit is contained in:
2
Makefile
2
Makefile
@@ -4,7 +4,7 @@ GOOS ?= $(shell $(GO) env GOOS)
|
|||||||
|
|
||||||
MAKEFILE := $(realpath $(lastword $(MAKEFILE_LIST)))
|
MAKEFILE := $(realpath $(lastword $(MAKEFILE_LIST)))
|
||||||
ROOT_DIR := $(shell dirname $(MAKEFILE))
|
ROOT_DIR := $(shell dirname $(MAKEFILE))
|
||||||
SOURCES := $(wildcard *.go src/*.go src/*/*.go shell/*sh) $(MAKEFILE)
|
SOURCES := $(wildcard *.go src/*.go src/*/*.go shell/*sh man/man1/*.1) $(MAKEFILE)
|
||||||
|
|
||||||
ifdef FZF_VERSION
|
ifdef FZF_VERSION
|
||||||
VERSION := $(FZF_VERSION)
|
VERSION := $(FZF_VERSION)
|
||||||
|
18
main.go
18
main.go
@@ -4,6 +4,7 @@ import (
|
|||||||
_ "embed"
|
_ "embed"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
fzf "github.com/junegunn/fzf/src"
|
fzf "github.com/junegunn/fzf/src"
|
||||||
@@ -28,6 +29,9 @@ var zshCompletion []byte
|
|||||||
//go:embed shell/key-bindings.fish
|
//go:embed shell/key-bindings.fish
|
||||||
var fishKeyBindings []byte
|
var fishKeyBindings []byte
|
||||||
|
|
||||||
|
//go:embed man/man1/fzf.1
|
||||||
|
var manPage []byte
|
||||||
|
|
||||||
func printScript(label string, content []byte) {
|
func printScript(label string, content []byte) {
|
||||||
fmt.Println("### " + label + " ###")
|
fmt.Println("### " + label + " ###")
|
||||||
fmt.Println(strings.TrimSpace(string(content)))
|
fmt.Println(strings.TrimSpace(string(content)))
|
||||||
@@ -76,6 +80,20 @@ func main() {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if options.Man {
|
||||||
|
file := fzf.WriteTemporaryFile([]string{string(manPage)}, "\n")
|
||||||
|
if len(file) == 0 {
|
||||||
|
fmt.Print(string(manPage))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer os.Remove(file)
|
||||||
|
cmd := exec.Command("man", file)
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
if err := cmd.Run(); err != nil {
|
||||||
|
fmt.Print(string(manPage))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
code, err := fzf.Run(options)
|
code, err := fzf.Run(options)
|
||||||
exit(code, err)
|
exit(code, err)
|
||||||
|
@@ -898,9 +898,16 @@ e.g.
|
|||||||
# Choose port automatically and export it as $FZF_PORT to the child process
|
# Choose port automatically and export it as $FZF_PORT to the child process
|
||||||
fzf --listen --bind 'start:execute-silent:echo $FZF_PORT > /tmp/fzf-port'
|
fzf --listen --bind 'start:execute-silent:echo $FZF_PORT > /tmp/fzf-port'
|
||||||
\fR
|
\fR
|
||||||
|
.SS Help
|
||||||
.TP
|
.TP
|
||||||
.B "--version"
|
.B "--version"
|
||||||
Display version information and exit
|
Display version information and exit
|
||||||
|
.TP
|
||||||
|
.B "--help"
|
||||||
|
Show help message
|
||||||
|
.TP
|
||||||
|
.B "--man"
|
||||||
|
Show man page
|
||||||
|
|
||||||
.SS Directory traversal
|
.SS Directory traversal
|
||||||
.TP
|
.TP
|
||||||
|
@@ -6,7 +6,7 @@ import (
|
|||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
func writeTemporaryFile(data []string, printSep string) string {
|
func WriteTemporaryFile(data []string, printSep string) string {
|
||||||
f, err := os.CreateTemp("", "fzf-temp-*")
|
f, err := os.CreateTemp("", "fzf-temp-*")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Unable to create temporary file
|
// Unable to create temporary file
|
||||||
|
@@ -127,7 +127,6 @@ const Usage = `usage: fzf [options]
|
|||||||
--with-shell=STR Shell command and flags to start child processes with
|
--with-shell=STR Shell command and flags to start child processes with
|
||||||
--listen[=[ADDR:]PORT] Start HTTP server to receive actions (POST /)
|
--listen[=[ADDR:]PORT] Start HTTP server to receive actions (POST /)
|
||||||
(To allow remote process execution, use --listen-unsafe)
|
(To allow remote process execution, use --listen-unsafe)
|
||||||
--version Display version information and exit
|
|
||||||
|
|
||||||
Directory traversal (Only used when $FZF_DEFAULT_COMMAND is not set)
|
Directory traversal (Only used when $FZF_DEFAULT_COMMAND is not set)
|
||||||
--walker=OPTS [file][,dir][,follow][,hidden] (default: file,follow,hidden)
|
--walker=OPTS [file][,dir][,follow][,hidden] (default: file,follow,hidden)
|
||||||
@@ -140,6 +139,11 @@ const Usage = `usage: fzf [options]
|
|||||||
--zsh Print script to set up Zsh shell integration
|
--zsh Print script to set up Zsh shell integration
|
||||||
--fish Print script to set up Fish shell integration
|
--fish Print script to set up Fish shell integration
|
||||||
|
|
||||||
|
Help
|
||||||
|
--version Display version information and exit
|
||||||
|
--help Show this message
|
||||||
|
--man Show man page
|
||||||
|
|
||||||
Environment variables
|
Environment variables
|
||||||
FZF_DEFAULT_COMMAND Default command to use when input is tty
|
FZF_DEFAULT_COMMAND Default command to use when input is tty
|
||||||
FZF_DEFAULT_OPTS Default options (e.g. '--layout=reverse --info=inline')
|
FZF_DEFAULT_OPTS Default options (e.g. '--layout=reverse --info=inline')
|
||||||
@@ -387,6 +391,7 @@ type Options struct {
|
|||||||
Bash bool
|
Bash bool
|
||||||
Zsh bool
|
Zsh bool
|
||||||
Fish bool
|
Fish bool
|
||||||
|
Man bool
|
||||||
Fuzzy bool
|
Fuzzy bool
|
||||||
FuzzyAlgo algo.Algo
|
FuzzyAlgo algo.Algo
|
||||||
Scheme string
|
Scheme string
|
||||||
@@ -493,6 +498,7 @@ func defaultOptions() *Options {
|
|||||||
Bash: false,
|
Bash: false,
|
||||||
Zsh: false,
|
Zsh: false,
|
||||||
Fish: false,
|
Fish: false,
|
||||||
|
Man: false,
|
||||||
Fuzzy: true,
|
Fuzzy: true,
|
||||||
FuzzyAlgo: algo.FuzzyMatchV2,
|
FuzzyAlgo: algo.FuzzyMatchV2,
|
||||||
Scheme: "default",
|
Scheme: "default",
|
||||||
@@ -1865,10 +1871,14 @@ func parseOptions(opts *Options, allArgs []string) error {
|
|||||||
opts.Fish = false
|
opts.Fish = false
|
||||||
opts.Help = false
|
opts.Help = false
|
||||||
opts.Version = false
|
opts.Version = false
|
||||||
|
opts.Man = false
|
||||||
}
|
}
|
||||||
for i := 0; i < len(allArgs); i++ {
|
for i := 0; i < len(allArgs); i++ {
|
||||||
arg := allArgs[i]
|
arg := allArgs[i]
|
||||||
switch arg {
|
switch arg {
|
||||||
|
case "--man":
|
||||||
|
clearExitingOpts()
|
||||||
|
opts.Man = true
|
||||||
case "--bash":
|
case "--bash":
|
||||||
clearExitingOpts()
|
clearExitingOpts()
|
||||||
opts.Bash = true
|
opts.Bash = true
|
||||||
|
@@ -98,7 +98,7 @@ func runProxy(commandPrefix string, cmdBuilder func(temp string) *exec.Cmd, opts
|
|||||||
exports[idx] = fmt.Sprintf("export %s=%s", pair[0], escapeSingleQuote(pair[1]))
|
exports[idx] = fmt.Sprintf("export %s=%s", pair[0], escapeSingleQuote(pair[1]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
temp := writeTemporaryFile(append(exports, command), "\n")
|
temp := WriteTemporaryFile(append(exports, command), "\n")
|
||||||
defer os.Remove(temp)
|
defer os.Remove(temp)
|
||||||
|
|
||||||
cmd := cmdBuilder(temp)
|
cmd := cmdBuilder(temp)
|
||||||
|
@@ -2840,7 +2840,7 @@ func replacePlaceholder(params replacePlaceholderParams) (string, []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if flags.file {
|
if flags.file {
|
||||||
file := writeTemporaryFile(replacements, params.printsep)
|
file := WriteTemporaryFile(replacements, params.printsep)
|
||||||
tempFiles = append(tempFiles, file)
|
tempFiles = append(tempFiles, file)
|
||||||
return file
|
return file
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user