Skip to content

Instantly share code, notes, and snippets.

@arika
Created April 26, 2009 11:48
Show Gist options
  • Save arika/102015 to your computer and use it in GitHub Desktop.
Save arika/102015 to your computer and use it in GitHub Desktop.
diff --git a/lib/capistrano/command.rb b/lib/capistrano/command.rb
index 8e0c61b..87a4c41 100644
--- a/lib/capistrano/command.rb
+++ b/lib/capistrano/command.rb
@@ -207,13 +207,15 @@ module Capistrano
if options[:shell] == false
shell = nil
+ shell, cmd = replace_environment(shell, cmd)
else
shell = "#{options[:shell] || "sh"} -c"
+ shell, cmd = replace_environment(shell, cmd)
cmd = cmd.gsub(/[$\\`"]/) { |m| "\\#{m}" }
cmd = "\"#{cmd}\""
end
- command_line = [environment, shell, cmd].compact.join(" ")
+ command_line = [shell, cmd].compact.join(" ")
ch[:command] = command_line
ch.exec(command_line)
@@ -261,6 +263,18 @@ module Capistrano
command.gsub(/\$CAPISTRANO:HOST\$/, channel[:host])
end
+ def replace_environment(shell, command)
+ cmd = command.gsub(/\$CAPISTRANO:ENV\$/, environment)
+ unless $&
+ if shell
+ shell = environment + " " + shell
+ else
+ cmd = environment + " " + cmd
+ end
+ end
+ [shell, cmd]
+ end
+
# prepare a space-separated sequence of variables assignments
# intended to be prepended to a command, so the shell sets
# the environment before running the command.
diff --git a/lib/capistrano/configuration/actions/invocation.rb b/lib/capistrano/configuration/actions/invocation.rb
index e43ba9d..16d6d9a 100644
--- a/lib/capistrano/configuration/actions/invocation.rb
+++ b/lib/capistrano/configuration/actions/invocation.rb
@@ -205,7 +205,7 @@ module Capistrano
sudo_command = [fetch(:sudo, "sudo"), sudo_prompt_option, user].compact.join(" ")
if command
- command = sudo_command + " " + command
+ command = sudo_command + " $CAPISTRANO:ENV$ " + command
run(command, options, &block)
else
return sudo_command
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment