diff --git a/lib/pry/command_processor.rb b/lib/pry/command_processor.rb index 84ea1560..79ee0fa5 100644 --- a/lib/pry/command_processor.rb +++ b/lib/pry/command_processor.rb @@ -12,6 +12,9 @@ class Pry 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) if val =~ /^\.(.*)/ execute_system_command($1) @@ -24,7 +27,11 @@ class Pry def execute_system_command(cmd) if cmd =~ /^cd\s+(.+)/i - Dir.chdir(File.expand_path($1)) + begin + Dir.chdir(File.expand_path($1)) + rescue Errno::ENOENT + output.puts "No such directory: #{$1}" + end else system(cmd) end diff --git a/lib/pry/commands.rb b/lib/pry/commands.rb index 9691ad34..d48df4ee 100644 --- a/lib/pry/commands.rb +++ b/lib/pry/commands.rb @@ -134,7 +134,6 @@ 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 @@ -413,9 +412,10 @@ Shows local and instance variables by default. ".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_type if file_type CodeRay.scan(contents, language_detected).term end @@ -443,11 +443,12 @@ Shows local and instance variables by default. 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= {} file_name = nil start_line = 0 end_line = -1 + file_type = nil OptionParser.new do |opts| opts.banner = %{Usage: cat-file [OPTIONS] FILE @@ -467,6 +468,10 @@ e.g: cat-file hello.rb end_line = line.to_i - 1 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 output.puts opts 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) 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 if options[:l] @@ -496,8 +501,6 @@ e.g: cat-file hello.rb contents end - alias_command ":cat", "cat-file", "" - command "eval-file", "Eval a Ruby script. Type `eval-file --help` for more info." do |*args| options = {} target = target() diff --git a/lib/pry/pry_class.rb b/lib/pry/pry_class.rb index a6ba06eb..dddcf6cc 100644 --- a/lib/pry/pry_class.rb +++ b/lib/pry/pry_class.rb @@ -57,6 +57,12 @@ class Pry # :after_session => proc { puts "goodbye" } 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 # Get the array of Procs to be used for the prompts by default by