1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

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
This commit is contained in:
John Mair 2011-04-07 15:31:03 +12:00
parent 2c54ab302f
commit 479c44a107
5 changed files with 43 additions and 29 deletions

3
TODO
View file

@ -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 file

@ -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"

View file

@ -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

View file

@ -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

View file

@ -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