diff --git a/lib/sshkit/command_map.rb b/lib/sshkit/command_map.rb
index <HASH>..<HASH> 100644
--- a/lib/sshkit/command_map.rb
+++ b/lib/sshkit/command_map.rb
@@ -39,7 +39,8 @@ module SSHKit
 
     def [](command)
       if prefix[command].any?
-        prefixes = prefix[command].join(" ")
+        prefixes = prefix[command].map{ |prefix| prefix.respond_to?(:call) ? prefix.call : prefix }
+        prefixes = prefixes.join(" ")
 
         "#{prefixes} #{command}"
       else
diff --git a/test/unit/test_command_map.rb b/test/unit/test_command_map.rb
index <HASH>..<HASH> 100644
--- a/test/unit/test_command_map.rb
+++ b/test/unit/test_command_map.rb
@@ -28,6 +28,14 @@ module SSHKit
       assert_equal map[:rake], "/home/vagrant/.rbenv/bin/rbenv exec bundle exec rake"
     end
 
+    def test_prefix_procs
+      map = CommandMap.new
+      map.prefix[:rake].push("/home/vagrant/.rbenv/bin/rbenv exec")
+      map.prefix[:rake].push(proc{ "bundle exec" })
+
+      assert_equal map[:rake], "/home/vagrant/.rbenv/bin/rbenv exec bundle exec rake"
+    end
+
     def test_prefix_unshift
       map = CommandMap.new
       map.prefix[:rake].push("bundle exec")
Added support for procs to command prefixes