Permalink
Browse files

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
  • Loading branch information...
1 parent 2c54ab3 commit 479c44a1072772541c026fce1972e78c0381e9a0 @banister banister committed Apr 7, 2011
Showing with 43 additions and 29 deletions.
  1. +3 −0 TODO
  2. +11 −11 lib/pry.rb
  3. +5 −16 lib/pry/commands.rb
  4. +2 −2 lib/pry/prompts.rb
  5. +22 −0 lib/pry/pry_instance.rb
View
@@ -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
View
@@ -20,14 +20,14 @@
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"
View
@@ -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 Commands < CommandBase
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
View
@@ -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
@@ -240,6 +240,26 @@ def set_last_exception(ex, target)
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 @@ def process_commands(val, eval_string, target)
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

0 comments on commit 479c44a

Please sign in to comment.