From 30bd0b53dbf804a96db4c13d787771b3924d6634 Mon Sep 17 00:00:00 2001
From: Junegunn Choi <junegunn.c@gmail.com>
Date: Wed, 3 Feb 2016 04:46:02 +0900
Subject: [PATCH] Fix #481 - Use $SHELL instead of sh in execute action

Note that $SHELL only points to the default shell instead of the current
shell. If you're on a non-default shell, you might want to override the
value like follows.

  SHELL=zsh fzf --bind 'enter:execute:echo $ZSH_VERSION; sleep 1'
---
 src/terminal.go |  6 +++++-
 test/test_go.rb | 16 ++++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/src/terminal.go b/src/terminal.go
index bd2ad15f..181b9c06 100644
--- a/src/terminal.go
+++ b/src/terminal.go
@@ -720,7 +720,11 @@ func quoteEntry(entry string) string {
 
 func executeCommand(template string, replacement string) {
 	command := strings.Replace(template, "{}", replacement, -1)
-	cmd := exec.Command("sh", "-c", command)
+	shell := os.Getenv("SHELL")
+	if len(shell) == 0 {
+		shell = "sh"
+	}
+	cmd := exec.Command(shell, "-c", command)
 	cmd.Stdin = os.Stdin
 	cmd.Stdout = os.Stdout
 	cmd.Stderr = os.Stderr
diff --git a/test/test_go.rb b/test/test_go.rb
index a8f75c64..5ea255aa 100644
--- a/test/test_go.rb
+++ b/test/test_go.rb
@@ -893,6 +893,22 @@ class TestGoFZF < TestBase
     File.unlink output rescue nil
   end
 
+  def test_execute_shell
+    # Custom script to use as $SHELL
+    output = tempname + '.out'
+    File.unlink output rescue nil
+    writelines tempname, ['#!/usr/bin/env bash', "echo $1 / $2 > #{output}"]
+    system "chmod +x #{tempname}"
+
+    tmux.send_keys "echo foo | SHELL=#{tempname} fzf --bind 'enter:execute:{}bar'", :Enter
+    tmux.until { |lines| lines[-2].include? '1/1' }
+    tmux.send_keys :Enter
+    tmux.send_keys 'C-c'
+    assert_equal ['-c / "foo"bar'], File.readlines(output).map(&:chomp)
+  ensure
+    File.unlink output rescue nil
+  end
+
   def test_cycle
     tmux.send_keys "seq 8 | #{fzf :cycle}", :Enter
     tmux.until { |lines| lines[-2].include? '8/8' }
-- 
GitLab