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

added more documentation, proper error message for failed .cd command, added -t option to cat-file command

This commit is contained in:
John Mair 2011-04-07 20:38:50 +12:00
parent 0da553688d
commit 1aa4a66ffc
3 changed files with 23 additions and 7 deletions

View file

@ -12,6 +12,9 @@ class Pry
def_delegators :@pry_instance, :commands, :nesting, :output def_delegators :@pry_instance, :commands, :nesting, :output
# Run a system command (shell command).
# @param [String] val The shell command to execute.
# @return [Boolean] Whether
def system_command(val) def system_command(val)
if val =~ /^\.(.*)/ if val =~ /^\.(.*)/
execute_system_command($1) execute_system_command($1)
@ -24,7 +27,11 @@ class Pry
def execute_system_command(cmd) def execute_system_command(cmd)
if cmd =~ /^cd\s+(.+)/i if cmd =~ /^cd\s+(.+)/i
begin
Dir.chdir(File.expand_path($1)) Dir.chdir(File.expand_path($1))
rescue Errno::ENOENT
output.puts "No such directory: #{$1}"
end
else else
system(cmd) system(cmd)
end end

View file

@ -134,7 +134,6 @@ class Pry
end end
end end
# FIXME: when restoring backups does not restore descriptions
command "file-mode", "Toggle file mode." do command "file-mode", "Toggle file mode." do
case Pry.active_instance.prompt case Pry.active_instance.prompt
when Pry::FILE_PROMPT when Pry::FILE_PROMPT
@ -413,9 +412,10 @@ Shows local and instance variables by default.
".json" => :json ".json" => :json
} }
syntax_highlight_by_file_type = lambda do |contents, file_name| syntax_highlight_by_file_type_or_specified = lambda do |contents, file_name, file_type|
_, language_detected = file_map.find { |k, v| Array(k).include?(File.extname(file_name)) } _, language_detected = file_map.find { |k, v| Array(k).include?(File.extname(file_name)) }
language_detected = file_type if file_type
CodeRay.scan(contents, language_detected).term CodeRay.scan(contents, language_detected).term
end end
@ -443,11 +443,12 @@ Shows local and instance variables by default.
end end
end end
command "cat-file", "Show output of file FILE. Type `cat --help` for more information. Aliases: :cat" do |*args| command "cat-file", "Show output of file FILE. Type `cat --help` for more information." do |*args|
options= {} options= {}
file_name = nil file_name = nil
start_line = 0 start_line = 0
end_line = -1 end_line = -1
file_type = nil
OptionParser.new do |opts| OptionParser.new do |opts|
opts.banner = %{Usage: cat-file [OPTIONS] FILE opts.banner = %{Usage: cat-file [OPTIONS] FILE
@ -467,6 +468,10 @@ e.g: cat-file hello.rb
end_line = line.to_i - 1 end_line = line.to_i - 1
end end
opts.on("-t", "--type TYPE", "The specific file type for syntax higlighting.") do |type|
file_type = type.to_sym
end
opts.on_tail("-h", "--help", "This message.") do opts.on_tail("-h", "--help", "This message.") do
output.puts opts output.puts opts
options[:h] = true options[:h] = true
@ -485,7 +490,7 @@ e.g: cat-file hello.rb
contents = read_between_the_lines.call(file_name, start_line, end_line, false) contents = read_between_the_lines.call(file_name, start_line, end_line, false)
if Pry.color if Pry.color
contents = syntax_highlight_by_file_type.call(contents, file_name) contents = syntax_highlight_by_file_type_or_specified.call(contents, file_name, file_type)
end end
if options[:l] if options[:l]
@ -496,8 +501,6 @@ e.g: cat-file hello.rb
contents contents
end end
alias_command ":cat", "cat-file", ""
command "eval-file", "Eval a Ruby script. Type `eval-file --help` for more info." do |*args| command "eval-file", "Eval a Ruby script. Type `eval-file --help` for more info." do |*args|
options = {} options = {}
target = target() target = target()

View file

@ -57,6 +57,12 @@ class Pry
# :after_session => proc { puts "goodbye" } # :after_session => proc { puts "goodbye" }
attr_accessor :hooks attr_accessor :hooks
# Get/Set the Proc that defines extra Readline completions (on top
# of the ones defined for IRB).
# @return [Proc] The Proc that defines extra Readline completions (on top
# @example Add file names to completion list
# Pry.custom_completions = proc { Dir.entries('.') }
attr_accessor :custom_completions attr_accessor :custom_completions
# Get the array of Procs to be used for the prompts by default by # Get the array of Procs to be used for the prompts by default by