Skip to content

Commit

Permalink
version 0.6.1(pre), added !! as alias for exit-all, added cd/ to retu…
Browse files Browse the repository at this point in the history
…rn to pry toplevel, improved `pry` command line so it uses a rep session on -e code
  • Loading branch information
banister committed Feb 25, 2011
1 parent 03ddbba commit 7ce581e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
6 changes: 6 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
0.6.1
* !! command alias for exit_all
* `cd /` for breaking out to pry top level (jump-to 0)
* `less` command? and pipe support?
* made `-e` option work in a more effective way for `pry` command line invocation

0.5.0 release:
* !!!! UPDATE DOCUMENTATION !!!!
* Use clipped version of Pry.view() for large objects
Expand Down
5 changes: 2 additions & 3 deletions bin/pry
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,9 @@ load rcpath if File.exists?(rcpath) && options[:loadrc]
# create the actual context
context = Pry.binding_for(eval(options[:context_string]))

# execute line of code, if provided with -e option
# run code passed with `-e`, if there is any.
if options[:code]
result = context.eval(options[:code])
puts "=> #{Pry.view(result)}"
Pry.new(:input => StringIO.new(options[:code]), :print => proc {}).rep(context)
end

# start the session
Expand Down
27 changes: 20 additions & 7 deletions lib/pry/commands.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
direc = File.dirname(__FILE__)
require "#{direc}/command_base"

require "optparse"
require "method_source"
require "#{direc}/command_base"
require "#{direc}/pry_instance"

class Pry

Expand Down Expand Up @@ -72,10 +75,12 @@ class Commands < CommandBase
output.puts "Pry version: #{Pry::VERSION} on Ruby #{RUBY_VERSION}."
end

command "exit-all", "End all nested Pry sessions." do
command "exit-all", "End all nested Pry sessions. Aliases: !!" do
throw(:breakout, 0)
end

alias_command "!!", "exit-all", ""

command "ls", "Show the list of vars in the current scope. Type `ls --help` for more info." do |*args|
options = {}

Expand Down Expand Up @@ -210,15 +215,15 @@ class Commands < CommandBase
if options[:v]

# verbose
info.each.sort_by { |k, v| v.last }.each do |k, v|
info.sort_by { |k, v| v.last }.each do |k, v|
if !v.first.empty?
output.puts "#{k}:\n--"
output.puts Pry.view(v.first)
output.puts
end
end

# plain
# plain
else
list = info.values.sort_by { |v| v.last }.map { |v| v.first }.inject(&:+)
output.puts Pry.view(list)
Expand All @@ -232,7 +237,9 @@ class Commands < CommandBase
next
end

output.puts File.read(file_name)
contents = File.read(file_name)
output.puts contents
contents
end

command "eval-file", "Eval a Ruby script. Type `eval-file --help` for more info." do |*args|
Expand Down Expand Up @@ -290,13 +297,19 @@ class Commands < CommandBase

alias_command "inspect", "cat", ""

command "cd", "Start a Pry session on VAR (use `cd ..` to go back)" do |obj|
command "cd", "Start a Pry session on VAR (use `cd ..` to go back and `cd /` to return to Pry top-level)" do |obj|
if !obj
output.puts "Must provide an object."
next
end

throw(:breakout, opts[:nesting].level) if obj == ".."

if obj == "/"
throw(:breakout, 1) if opts[:nesting].level > 0
next
end

target.eval("#{obj}.pry")
end

Expand Down Expand Up @@ -515,7 +528,7 @@ class Commands < CommandBase
that if you turn your head
they are lost for hours.
-- Leonard Cohen
}
}
output.puts text
text
end
Expand Down
2 changes: 1 addition & 1 deletion lib/pry/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class Pry
VERSION = "0.6.0"
VERSION = "0.6.1pro1"
end

0 comments on commit 7ce581e

Please sign in to comment.