Update FZF_DEFAULT_COMMAND
Before adoption: this commit came in with the history the project adopted, so no landing records it.
- Use bash for `set -o pipefail` - Fall back to simpler find command when the original command failed
authored by Junegunn Choi · committed by Junegunn Choi · parent 7f5f6ef · Browse files · 5 files·+21 added−8 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Trailers
- Related: #1061
Diff stats
5 files+21 added−8 removed
- other:+21 added−8 removed
Provenance
- Commit
ee40212- Tree
799667b- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
7f5f6ef
5 files changed+21 added−8 removed
modified:src/util/util_unix.go+5 added
12 unmodified lines13 shell := os.Getenv("SHELL")14 if len(shell) == 0 {15 shell = "sh"16 }17+ return ExecCommandWith(shell, command)18+}19+20+// ExecCommandWith executes the given command with the specified shell21+func ExecCommandWith(shell string, command string) *exec.Cmd {22 return exec.Command(shell, "-c", command)23 }24 25 // IsWindows returns true on Windows13 unmodified linesmodified:src/util/util_windows.go+7 added-1 removed
8 unmodified lines9 10 "github.com/mattn/go-shellwords"11 )12 13-// ExecCommand executes the given command with $SHELL13+// ExecCommand executes the given command with cmd14 func ExecCommand(command string) *exec.Cmd {15+ return ExecCommandWith("cmd", command)16+}17+18+// ExecCommandWith executes the given command with cmd. _shell parameter is19+// ignored on Windows.20+func ExecCommandWith(_shell string, command string) *exec.Cmd {21 args, _ := shellwords.Parse(command)22 allArgs := make([]string, len(args)+1)23 allArgs[0] = "/c"24 copy(allArgs[1:], args)17 unmodified linesmodified:src/constants.go+1 added-1 removed
53 unmodified lines54 var defaultCommand string55 56 func init() {57 if !util.IsWindows() {58- defaultCommand = `command find -L . -mindepth 1 \( -path '*/\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \) -prune -o -type f -print -o -type l -print 2> /dev/null | cut -b3-`58+ defaultCommand = `set -o pipefail; (command find -L . -mindepth 1 \( -path '*/\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \) -prune -o -type f -print -o -type l -print || command find -L . -mindepth 1 -path '*/\.*' -prune -o -type f -print -o -type l -print) 2> /dev/null | cut -b3-`59 } else if os.Getenv("TERM") == "cygwin" {60 defaultCommand = `sh -c "command find -L . -mindepth 1 -path '*/\.*' -prune -o -type f -print -o -type l -print 2> /dev/null | cut -b3-"`61 } else {62 defaultCommand = `dir /s/b`20 unmodified linesmodified:src/reader_test.go+2 added-2 removed
21 unmodified lines22 t.Error("EvtReadNew should not be set yet")23 }24 25 // Normal command26- reader.fin(reader.readFromCommand(`echo abc && echo def`))26+ reader.fin(reader.readFromCommand("sh", `echo abc && echo def`))27 if len(strs) != 2 || strs[0] != "abc" || strs[1] != "def" {28 t.Errorf("%s", strs)29 }30 16 unmodified lines47 // Restart event poller48 reader.startEventPoller()49 50 // Failing command51- reader.fin(reader.readFromCommand(`no-such-command`))51+ reader.fin(reader.readFromCommand("sh", `no-such-command`))52 strs = []string{}53 if len(strs) > 0 {54 t.Errorf("%s", strs)55 }9 unmodified linesmodified:src/reader.go+6 added-4 removed
54 unmodified lines55 var success bool56 if util.IsTty() {57 cmd := os.Getenv("FZF_DEFAULT_COMMAND")58 if len(cmd) == 0 {59- cmd = defaultCommand59+ // The default command for *nix requires bash60+ success = r.readFromCommand("bash", defaultCommand)61+ } else {62+ success = r.readFromCommand("sh", cmd)63 }61- success = r.readFromCommand(cmd)64 } else {65 success = r.readFromStdin()66 }67 r.fin(success)33 unmodified lines101 r.feed(os.Stdin)102 return true103 }104 103-func (r *Reader) readFromCommand(cmd string) bool {104- listCommand := util.ExecCommand(cmd)105+func (r *Reader) readFromCommand(shell string, cmd string) bool {106+ listCommand := util.ExecCommandWith(shell, cmd)107 out, err := listCommand.StdoutPipe()108 if err != nil {109 return false110 }7 unmodified lines