diff --git a/TODO b/TODO index 7f45cfa2..b30292b8 100644 --- a/TODO +++ b/TODO @@ -3,6 +3,8 @@ FUTURE * allows pipes (|) for commands 0.8.0 +* allow #{} interpolation of all commands +* update documentation! new commands and features and change in behaviour of `run` * add ; at end of line to suppress return value output * Remove message spam (before/after hooks) * stop commands returning a value diff --git a/lib/pry/command_base.rb b/lib/pry/command_base.rb index 60cf75dc..b7541bfa 100644 --- a/lib/pry/command_base.rb +++ b/lib/pry/command_base.rb @@ -83,7 +83,7 @@ class Pry command_processor = CommandProcessor.new(target.eval('_pry_')) if command_processor.system_command?(name) - command_processor.execute_system_command("#{name} #{args.join}") + command_processor.execute_system_command("#{name} #{args.join}", target) else action = opts[:commands][name][:action] instance_exec(*args, &action) diff --git a/lib/pry/command_processor.rb b/lib/pry/command_processor.rb index e080b12e..30bb7a91 100644 --- a/lib/pry/command_processor.rb +++ b/lib/pry/command_processor.rb @@ -26,10 +26,16 @@ class Pry def pry_command?(val) !!command_matched(val).first end + + def interpolate_string(str, target) + dumped_str = str.dump + dumped_str.gsub!(/\\\#{/, '#{') + target.eval(dumped_str) + end - def execute_system_command(val) + def execute_system_command(val, target) SYSTEM_COMMAND_REGEX =~ val - cmd = $1 + cmd = interpolate_string($1, target) if cmd =~ /^cd\s+(.+)/i begin @@ -71,15 +77,16 @@ class Pry def eval_string.clear() replace("") end if system_command?(val) - execute_system_command(val) + execute_system_command(val, target) return end + # no command was matched, so return to caller + return if !pry_command?(val) + + val.replace interpolate_string(val, target) cmd_data, args_string = command_matched(val) - # no command was matched, so return to caller - return if !cmd_data - args = args_string ? Shellwords.shellwords(args_string) : [] action = cmd_data[:action] keep_retval = cmd_data[:keep_retval]