Repository: junegunn/fzf
File: src/util/util_unix.go (Go)

Code before:
		// https://fishshell.com/docs/current/language.html#quotes
		// > The only meaningful escape sequences in single quotes are \', which
		// > escapes a single quote and \\, which escapes the backslash symbol.
		escaper = strings.NewReplacer("\\", "\\\\", "'", "\\'")
	} else {
		escaper = strings.NewReplacer("'", "'\\''")
	}
	return &Executor{shell, args, escaper}
}

// ExecCommand executes the given command with $SHELL
func (x *Executor) ExecCommand(command string, setpgid bool) *exec.Cmd {
	cmd := exec.Command(x.shell, append(x.args, command)...)
	if setpgid {
		cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
	}
	return cmd
}

func (x *Executor) QuoteEntry(entry string) string {
	return "'" + x.escaper.Replace(entry) + "'"
}

func (x *Executor) Become(stdin *os.File, environ []string, command string) {
	SetStdin(stdin)
	shellPath, err := exec.LookPath(x.shell)
	if err == nil {
		shellPath = x.shell
	}
	args := append([]string{shellPath}, append(x.args, command)...)
	syscall.Exec(shellPath, args, environ)
}

// KillCommand kills the process for the given command
func KillCommand(cmd *exec.Cmd) error {
	return syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL)
}

// IsWindows returns true on Windows
func IsWindows() bool {
	return false
}

// SetNonblock executes syscall.SetNonblock on file descriptor
func SetNonblock(file *os.File, nonblock bool) {
	syscall.SetNonblock(int(file.Fd()), nonblock)
}

// Read executes syscall.Read on file descriptor
func Read(fd int, b []byte) (int, error) {
	return syscall.Read(int(fd), b)

Review comment (suggestion):
This works as long as the user provides the full path to their binary.

```bash
fzf --with-shell '/usr/bin/ruby -e' --bind 'enter:become:puts "Hello world"'
```
However, if the user only provides the name, then the execution stalls for the `become` part.

```bash
fzf --with-shell 'ruby -e' --bind 'enter:become:puts "Hello world"'
```

How about this ?

```go
	if err != nil {
		return
	}
```

Code after:
	if tokens[len(tokens)-1] == "fish" {
		// https://fishshell.com/docs/current/language.html#quotes
		// > The only meaningful escape sequences in single quotes are \', which
		// > escapes a single quote and \\, which escapes the backslash symbol.
		escaper = strings.NewReplacer("\\", "\\\\", "'", "\\'")
	} else {
		escaper = strings.NewReplacer("'", "'\\''")
	}
	return &Executor{shell, args, escaper}
}

// ExecCommand executes the given command with $SHELL
func (x *Executor) ExecCommand(command string, setpgid bool) *exec.Cmd {
	cmd := exec.Command(x.shell, append(x.args, command)...)
	if setpgid {
		cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
	}
	return cmd
}

func (x *Executor) QuoteEntry(entry string) string {
	return "'" + x.escaper.Replace(entry) + "'"
}

func (x *Executor) Become(stdin *os.File, environ []string, command string) {
	shellPath, err := exec.LookPath(x.shell)
	if err != nil {
		fmt.Fprintf(os.Stderr, "fzf (become): %s\n", err.Error())
		Exit(127)
	}
	args := append([]string{shellPath}, append(x.args, command)...)
	SetStdin(stdin)
	syscall.Exec(shellPath, args, environ)
}

// KillCommand kills the process for the given command
func KillCommand(cmd *exec.Cmd) error {
	return syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL)
}

// IsWindows returns true on Windows
func IsWindows() bool {
	return false
}

// SetNonblock executes syscall.SetNonblock on file descriptor
func SetNonblock(file *os.File, nonblock bool) {
	syscall.SetNonblock(int(file.Fd()), nonblock)
}

// Read executes syscall.Read on file descriptor