From 479c44a1072772541c026fce1972e78c0381e9a0 Mon Sep 17 00:00:00 2001 From: John Mair Date: Thu, 7 Apr 2011 15:31:03 +1200 Subject: [PATCH] added execution of shell commands when ':' is first char of command, forwards to system(). Added back in #{direc} before requires as without it the installed gems were interferring --- TODO | 3 +++ lib/pry.rb | 22 +++++++++++----------- lib/pry/commands.rb | 21 +++++---------------- lib/pry/prompts.rb | 4 ++-- lib/pry/pry_instance.rb | 22 ++++++++++++++++++++++ 5 files changed, 43 insertions(+), 29 deletions(-) diff --git a/TODO b/TODO index 2f864135..87a258bf 100644 --- a/TODO +++ b/TODO @@ -5,6 +5,9 @@ FUTURE documentation; fix this 0.8.0 +* shell functionality should just use system(), but redirect in and + out to Pry.input and Pry.output by reassining $stdin and $stdout + for duration of block. * basicobject and no to_s/inspect support * fix documentation, support rdoc and yard properly * only load Ripper if 1.9 AND MRI (support jruby 1.9, using diff --git a/lib/pry.rb b/lib/pry.rb index f3657b9c..788a7705 100644 --- a/lib/pry.rb +++ b/lib/pry.rb @@ -20,14 +20,14 @@ if RUBY_PLATFORM =~ /mswin/ || RUBY_PLATFORM =~ /mingw/ end end -require "pry/version" -require "pry/hooks" -require "pry/print" -require "pry/command_base" -require "pry/commands" -require "pry/prompts" -require "pry/custom_completions" -require "pry/completion" -require "pry/core_extensions" -require "pry/pry_class" -require "pry/pry_instance" +require "#{direc}/pry/version" +require "#{direc}/pry/hooks" +require "#{direc}/pry/print" +require "#{direc}/pry/command_base" +require "#{direc}/pry/commands" +require "#{direc}/pry/prompts" +require "#{direc}/pry/custom_completions" +require "#{direc}/pry/completion" +require "#{direc}/pry/core_extensions" +require "#{direc}/pry/pry_class" +require "#{direc}/pry/pry_instance" diff --git a/lib/pry/commands.rb b/lib/pry/commands.rb index 48ecb14b..64ad3634 100644 --- a/lib/pry/commands.rb +++ b/lib/pry/commands.rb @@ -1,7 +1,9 @@ +direc = File.dirname(__FILE__) + require "optparse" require "method_source" -require "pry/command_base" -require "pry/pry_instance" +require "#{direc}/command_base" +require "#{direc}/pry_instance" begin @@ -17,20 +19,6 @@ class Pry # Default commands used by Pry. class Commands < CommandBase - # hidden commands for file-system interaction - command ":cd", "" do |direc| - Dir.chdir File.expand_path(direc) - output.puts direc - end - - command ":ls", "" do - output.puts Dir.entries('.') - end - - command ":pwd", "" do - output.puts Dir.pwd - end - # We make this a lambda to avoid documenting it meth_name_from_binding = lambda do |b| meth_name = b.eval('__method__') @@ -146,6 +134,7 @@ class Pry end end + # FIXME: when restoring backups does not restore descriptions command "file-mode", "Toggle file mode." do case Pry.active_instance.prompt when Pry::FILE_PROMPT diff --git a/lib/pry/prompts.rb b/lib/pry/prompts.rb index 65fdd0d1..2afdfe4c 100644 --- a/lib/pry/prompts.rb +++ b/lib/pry/prompts.rb @@ -25,7 +25,7 @@ class Pry SIMPLE_PROMPT = [proc { ">> " }, proc { ">* " }] FILE_PROMPT = [ - proc { |target_self, _| "pry(#{Pry.view_clip(target_self)}:#{Dir.pwd}> " }, - proc { |target_self, _| "pry(#{Pry.view_clip(target_self)}:#{Dir.pwd}* " } + proc { |target_self, _| "pry #{Pry.view_clip(target_self)}:#{Dir.pwd} $ " }, + proc { |target_self, _| "pry #{Pry.view_clip(target_self)}:#{Dir.pwd} * " } ] end diff --git a/lib/pry/pry_instance.rb b/lib/pry/pry_instance.rb index ec44eb12..99eaf4d1 100644 --- a/lib/pry/pry_instance.rb +++ b/lib/pry/pry_instance.rb @@ -240,6 +240,26 @@ class Pry target.eval("_ex_ = ::Pry.last_exception") end + # FIXME + def system_command(val) + if val =~ /^:(.*)/ + execute_system_command($1) + val.clear + else + return false + end + true + end + + def execute_system_command(cmd) + if cmd =~ /^cd\s+(.+)/i + Dir.chdir(File.expand_path($1)) + system(cmd) + else + system(cmd) + end + end + # Determine whether a Pry command was matched and return command data # and argument string. # This method should not need to be invoked directly. @@ -266,6 +286,8 @@ class Pry def val.clear() replace("") end def eval_string.clear() replace("") end + return if system_command(val) + cmd_data, args_string = command_matched(val) # no command was matched, so return to caller