Skip to content
Myr

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

5 files+21 added−8 removed

modified:src/util/util_unix.go+5 added
12 unmodified lines
13 shell := os.Getenv("SHELL")14 if len(shell) == 0 {15 shell = "sh"16 }17 return ExecCommandWith(shell, command)18}1920// ExecCommandWith executes the given command with the specified shell21func ExecCommandWith(shell string, command string) *exec.Cmd {22 return exec.Command(shell, "-c", command)23}2425// IsWindows returns true on Windows
13 unmodified lines
modified:src/util/util_windows.go+7 added-1 removed
8 unmodified lines
910 "github.com/mattn/go-shellwords"11)1213// ExecCommand executes the given command with $SHELL13// ExecCommand executes the given command with cmd14func ExecCommand(command string) *exec.Cmd {15 return ExecCommandWith("cmd", command)16}1718// ExecCommandWith executes the given command with cmd. _shell parameter is19// ignored on Windows.20func 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 lines
modified:src/constants.go+1 added-1 removed
53 unmodified lines
54var defaultCommand string5556func 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 lines
modified:src/reader_test.go+2 added-2 removed
21 unmodified lines
22 t.Error("EvtReadNew should not be set yet")23 }2425 // 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 lines
47 // Restart event poller48 reader.startEventPoller()4950 // 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 lines
modified:src/reader.go+6 added-4 removed
54 unmodified lines
55 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 lines
101 r.feed(os.Stdin)102 return true103}104103func (r *Reader) readFromCommand(cmd string) bool {104 listCommand := util.ExecCommand(cmd)105func (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