Skip to content
Myr

Embed man page in the binary and show it on 'fzf --man'

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Junegunn Choi · committed by Junegunn Choi · parent 7b0c9e0 · Browse files · 7 files+40 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

7 files+40 added−5 removed

  • other:+40 added−5 removed

7 files+40 added−5 removed

modified:man/man1/fzf.1+7 added
896 unmodified lines
897898 # Choose port automatically and export it as $FZF_PORT to the child process899 fzf --listen --bind 'start:execute-silent:echo $FZF_PORT > /tmp/fzf-port'900 \fR901.SS Help902.TP903.B "--version"904Display version information and exit905.TP906.B "--help"907Show help message908.TP909.B "--man"910Show man page911912.SS Directory traversal913.TP914.B "--walker=[file][,dir][,follow][,hidden]"
695 unmodified lines
modified:src/functions.go+1 added-1 removed
4 unmodified lines
5 "strings"6 "unsafe"7)89func writeTemporaryFile(data []string, printSep string) string {9func WriteTemporaryFile(data []string, printSep string) string {10 f, err := os.CreateTemp("", "fzf-temp-*")11 if err != nil {12 // Unable to create temporary file13 // FIXME: Should we terminate the program?
22 unmodified lines
modified:src/options.go+11 added-1 removed
125 unmodified lines
126 --sync Synchronous search for multi-staged filtering127 --with-shell=STR Shell command and flags to start child processes with128 --listen[=[ADDR:]PORT] Start HTTP server to receive actions (POST /)129 (To allow remote process execution, use --listen-unsafe)130 --version Display version information and exit130131 Directory traversal (Only used when $FZF_DEFAULT_COMMAND is not set)132 --walker=OPTS [file][,dir][,follow][,hidden] (default: file,follow,hidden)133 --walker-root=DIR Root directory from which to start walker (default: .)
4 unmodified lines
138 --bash Print script to set up Bash shell integration139 --zsh Print script to set up Zsh shell integration140 --fish Print script to set up Fish shell integration141142 Help143 --version Display version information and exit144 --help Show this message145 --man Show man page146147 Environment variables148 FZF_DEFAULT_COMMAND Default command to use when input is tty149 FZF_DEFAULT_OPTS Default options (e.g. '--layout=reverse --info=inline')150 FZF_DEFAULT_OPTS_FILE Location of the file to read default options from
239 unmodified lines
390 ProxyScript string391 Bash bool392 Zsh bool393 Fish bool394 Man bool395 Fuzzy bool396 FuzzyAlgo algo.Algo397 Scheme string398 Extended bool
98 unmodified lines
497 return &Options{498 Bash: false,499 Zsh: false,500 Fish: false,501 Man: false,502 Fuzzy: true,503 FuzzyAlgo: algo.FuzzyMatchV2,504 Scheme: "default",505 Extended: true,
1364 unmodified lines
1870 opts.Zsh = false1871 opts.Fish = false1872 opts.Help = false1873 opts.Version = false1874 opts.Man = false1875 }1876 for i := 0; i < len(allArgs); i++ {1877 arg := allArgs[i]1878 switch arg {1879 case "--man":1880 clearExitingOpts()1881 opts.Man = true1882 case "--bash":1883 clearExitingOpts()1884 opts.Bash = true1885 case "--zsh":
911 unmodified lines
modified:src/proxy.go+1 added-1 removed
96 unmodified lines
97 pair := strings.SplitN(pairStr, "=", 2)98 exports[idx] = fmt.Sprintf("export %s=%s", pair[0], escapeSingleQuote(pair[1]))99 }100 }101 temp := writeTemporaryFile(append(exports, command), "\n")101 temp := WriteTemporaryFile(append(exports, command), "\n")102 defer os.Remove(temp)103104 cmd := cmdBuilder(temp)105 if err := cmd.Run(); err != nil {
27 unmodified lines
modified:src/terminal.go+1 added-1 removed
2838 unmodified lines
2839 replacements[idx] = replace(item)2840 }28412842 if flags.file {2843 file := writeTemporaryFile(replacements, params.printsep)2843 file := WriteTemporaryFile(replacements, params.printsep)2844 tempFiles = append(tempFiles, file)2845 return file2846 }2847 return strings.Join(replacements, " ")
1747 unmodified lines
modified:main.go+18 added
2 unmodified lines
3import (4 _ "embed"5 "fmt"6 "os"7 "os/exec"8 "strings"910 fzf "github.com/junegunn/fzf/src"11 "github.com/junegunn/fzf/src/protector"
16 unmodified lines
2829//go:embed shell/key-bindings.fish30var fishKeyBindings []byte3132//go:embed man/man1/fzf.133var manPage []byte3435func printScript(label string, content []byte) {36 fmt.Println("### " + label + " ###")37 fmt.Println(strings.TrimSpace(string(content)))38 fmt.Println("### end: " + label + " ###")
40 unmodified lines
79 fmt.Println(version)80 }81 return82 }83 if options.Man {84 file := fzf.WriteTemporaryFile([]string{string(manPage)}, "\n")85 if len(file) == 0 {86 fmt.Print(string(manPage))87 return88 }89 defer os.Remove(file)90 cmd := exec.Command("man", file)91 cmd.Stdout = os.Stdout92 if err := cmd.Run(); err != nil {93 fmt.Print(string(manPage))94 }95 return96 }9798 code, err := fzf.Run(options)99 exit(code, err)100}
modified:Makefile+1 added-1 removed
2 unmodified lines
3GOOS ?= $(shell $(GO) env GOOS)45MAKEFILE := $(realpath $(lastword $(MAKEFILE_LIST)))6ROOT_DIR := $(shell dirname $(MAKEFILE))7SOURCES := $(wildcard *.go src/*.go src/*/*.go shell/*sh) $(MAKEFILE)7SOURCES := $(wildcard *.go src/*.go src/*/*.go shell/*sh man/man1/*.1) $(MAKEFILE)89ifdef FZF_VERSION10VERSION := $(FZF_VERSION)11else
176 unmodified lines