From 7cbb4be5b9d1fd7ded7cbc36ebece58cbe8fa001 Mon Sep 17 00:00:00 2001 From: Michael Yockey Date: Thu, 20 Jul 2023 16:10:26 -0400 Subject: [PATCH] Add AwesomePrint support to Pry --- pryrc | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/pryrc b/pryrc index a10a90a..0c6170c 100644 --- a/pryrc +++ b/pryrc @@ -1,6 +1,18 @@ # frozen_string_literal: true -require 'awesome_print' +# Locate the gem directory for the current Ruby version and add the awesome_print directory to load path +version_path_prefix = RbConfig::CONFIG['prefix'] +base_version = File.basename(version_path_prefix).tap { |basename| basename[-1] = '0' } +gems_path = File.join(version_path_prefix, 'lib', 'ruby', 'gems', base_version, 'gems') +ap_gem_dir_name = Dir.new(gems_path).children.detect { |file| file.start_with? 'awesome_print' } -Pry.print = proc { |output, value| output.puts value.ai({ limit: true }) } +if ap_gem_dir_name.nil? + puts 'Could not find AwesonePrint gem in this environment' +else + $LOAD_PATH << File.join(gems_path, ap_gem_dir_name, 'lib') + require 'awesome_print' + + Pry.print = proc { |output, value| output.puts value.ai({ limit: true }) } + puts 'AwesomePrint available in this session' +end Pry.config.editor = proc { |file, line| "code --wait --goto #{file}:#{line} --disable-workspace-trust" }