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
Provenance
- Commit
076b3d0- Tree
af30be1- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
7b0c9e0
7 files changed+40 added−5 removed
modified:man/man1/fzf.1+7 added
896 unmodified lines897 898 # 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"904 Display version information and exit905+.TP906+.B "--help"907+Show help message908+.TP909+.B "--man"910+Show man page911 912 .SS Directory traversal913 .TP914 .B "--walker=[file][,dir][,follow][,hidden]"695 unmodified linesmodified:src/functions.go+1 added-1 removed
4 unmodified lines5 "strings"6 "unsafe"7 )8 9-func writeTemporaryFile(data []string, printSep string) string {9+func 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 linesmodified:src/options.go+11 added-1 removed
125 unmodified lines126 --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 exit130 131 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 lines138 --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 integration141 142+ Help143+ --version Display version information and exit144+ --help Show this message145+ --man Show man page146+147 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 from239 unmodified lines390 ProxyScript string391 Bash bool392 Zsh bool393 Fish bool394+ Man bool395 Fuzzy bool396 FuzzyAlgo algo.Algo397 Scheme string398 Extended bool98 unmodified lines497 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 lines1870 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 linesmodified:src/proxy.go+1 added-1 removed
96 unmodified lines97 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)103 104 cmd := cmdBuilder(temp)105 if err := cmd.Run(); err != nil {27 unmodified linesmodified:src/terminal.go+1 added-1 removed
2838 unmodified lines2839 replacements[idx] = replace(item)2840 }2841 2842 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 linesmodified:main.go+18 added
2 unmodified lines3 import (4 _ "embed"5 "fmt"6 "os"7+ "os/exec"8 "strings"9 10 fzf "github.com/junegunn/fzf/src"11 "github.com/junegunn/fzf/src/protector"16 unmodified lines28 29 //go:embed shell/key-bindings.fish30 var fishKeyBindings []byte31 32+//go:embed man/man1/fzf.133+var manPage []byte34+35 func printScript(label string, content []byte) {36 fmt.Println("### " + label + " ###")37 fmt.Println(strings.TrimSpace(string(content)))38 fmt.Println("### end: " + label + " ###")40 unmodified lines79 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+ }97 98 code, err := fzf.Run(options)99 exit(code, err)100 }modified:Makefile+1 added-1 removed
2 unmodified lines3 GOOS ?= $(shell $(GO) env GOOS)4 5 MAKEFILE := $(realpath $(lastword $(MAKEFILE_LIST)))6 ROOT_DIR := $(shell dirname $(MAKEFILE))7-SOURCES := $(wildcard *.go src/*.go src/*/*.go shell/*sh) $(MAKEFILE)7+SOURCES := $(wildcard *.go src/*.go src/*/*.go shell/*sh man/man1/*.1) $(MAKEFILE)8 9 ifdef FZF_VERSION10 VERSION := $(FZF_VERSION)11 else176 unmodified lines