├── .gitignore ├── Gemfile ├── LICENSE.txt ├── README.md ├── Rakefile ├── jazz_hands2.gemspec └── lib ├── jazz_hands2.rb └── jazz_hands2 ├── hirb_ext.rb ├── railtie.rb └── version.rb /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /.yardoc 3 | /Gemfile.lock 4 | /_yardoc/ 5 | /coverage/ 6 | /doc/ 7 | /pkg/ 8 | /spec/reports/ 9 | /tmp/ 10 | *.bundle 11 | *.so 12 | *.o 13 | *.a 14 | mkmf.log 15 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in jazz_hands2.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 Enrico Carlesso 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JazzHands2 2 | 3 | JazzHands2 aims to be the successor of the abandoned [JazzHand2](https://github.com/nixme/jazz_hands) 4 | 5 | The dependencies has been updated, this only supports Ruby 2+. 6 | 7 | Some of the codes comes from the [new_jazz_hands](https://github.com/billywatson/jazz_hands) gem, but without 8 | some conflict in names. 9 | 10 | List of gems included: 11 | 12 | * [**Pry**][pry] for a powerful shell alternative to IRB. 13 | * [**Hirb**][hirb] for tabular collection output. 14 | * [**Pry Rails**][pry-rails] for additional commands (`show-routes`, 15 | `show-models`, `show-middleware`) in the Rails console. 16 | * [**Pry Doc**][pry-doc] to browse Ruby source, including C, directly from the 17 | console. 18 | * [**Pry Git**][pry-git] to teach the console about git. Diffs, blames, and 19 | commits on methods and classes, not just files. 20 | * [**Pry Remote**][pry-remote] to connect remotely to a Pry console. 21 | * [**Pry Debugger**][pry-debugger] to turn the console into a simple debugger. 22 | * [**Pry Stack Explorer**][pry-stack_explorer] to navigate the call stack and 23 | frames. 24 | 25 | ## Usage 26 | 27 | Ruby 2+, Rails 3, 4 only. 28 | 29 | Add this line to your application's Gemfile: 30 | 31 | ```ruby 32 | group :development, :test do # well, this can be useful in production too... 33 | gem 'jazz_hands2' 34 | end 35 | ``` 36 | 37 | And then execute: 38 | 39 | $ bundle 40 | 41 | From now on, firing up a `rails console` will require all the gems above and turns on `Hirb`. You can disable `Hirb` 42 | if you want with a `Hirb.disable`. 43 | 44 | In my experience is much better to turn off it a couple of times instead of needing to turn on it all the times except a couple. 45 | 46 | **Note:** even if [**AwesomePrint**] is a wonderful gem, due some existing bugs it is not included. 47 | [eoinkelly](https://github.com/eoinkelly/awesome_print) forks seems to work fine and solve a lot of issues 48 | while we wait for AwesomePrint v2, from the readme: 49 | 50 | > **NOTE:** awesome_print v1.2.0 is the last release supporting Ruby versions prior to v1.9.3 and Rails versions prior to v3.0. The upcoming awesome_print v2.0 will require Ruby v1.9.3 or later and Rails v3.0 or later. 51 | 52 | So if you are an AwesomePrint addicted, add this to your gemfile: 53 | 54 | ```ruby 55 | group :development, :test do # well, this can be useful in production too... 56 | gem 'jazz_hands2' 57 | gem 'awesome_print', github: 'eoinkelly/awesome_print' 58 | end 59 | ``` 60 | 61 | **Don't** call `AwesomePrint.pry!`, the `railtie.rb` automatically uses AwesomePrint if present. 62 | 63 | ## Contributing 64 | 65 | 1. Fork it ( https://github.com/[my-github-username]/jazz_hands2/fork ) 66 | 2. Create your feature branch (`git checkout -b my-new-feature`) 67 | 3. Commit your changes (`git commit -am 'Add some feature'`) 68 | 4. Push to the branch (`git push origin my-new-feature`) 69 | 5. Create a new Pull Request 70 | 71 | 72 | [pry]: http://pry.github.com 73 | [awesome_print]: https://github.com/michaeldv/awesome_print 74 | [hirb]: https://github.com/cldwalker/hirb 75 | [pry-rails]: https://github.com/rweng/pry-rails 76 | [pry-doc]: https://github.com/pry/pry-doc 77 | [pry-git]: https://github.com/pry/pry-git 78 | [pry-debugger]: https://github.com/nixme/pry-debugger 79 | [pry-remote]: https://github.com/Mon-Ouie/pry-remote 80 | [pry-stack_explorer]: https://github.com/pry/pry-stack_explorer 81 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | 3 | -------------------------------------------------------------------------------- /jazz_hands2.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require 'jazz_hands2/version' 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = "jazz_hands2" 8 | spec.version = JazzHands2::VERSION 9 | spec.authors = ["Enrico Carlesso"] 10 | spec.email = ["enricocarlesso@gmail.com"] 11 | spec.summary = "Successor of abandoned jazz_hands gem. Exercise those fingers. Pry-based enhancements for the default Rails console." 12 | spec.description = 'Spending hours in the rails console? Spruce it up and '\ 13 | 'show off those hard-working hands! jazz_hands replaces IRB with Pry, '\ 14 | 'improves output through awesome_print, and has some other goodies up its '\ 15 | 'sleeves. Only Ruby >= 2' 16 | spec.homepage = "https://github.com/coders51/jazz_hands2" 17 | spec.license = "MIT" 18 | 19 | spec.files = `git ls-files -z`.split("\x0") 20 | spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } 21 | spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) 22 | spec.require_paths = ["lib"] 23 | 24 | spec.required_ruby_version = '>= 2.0.0' 25 | spec.add_development_dependency "bundler", "~> 1.7" 26 | spec.add_development_dependency "rake", "~> 10.0" 27 | spec.add_runtime_dependency 'pry', '~> 0.10', '>= 0.10.1' 28 | spec.add_runtime_dependency 'pry-rails', '~> 0.3', '>= 0.3.4' 29 | spec.add_runtime_dependency 'pry-doc', '~> 0.8', '>= 0.8.0' 30 | spec.add_runtime_dependency 'pry-git', '~> 0.2', '>= 0.2.3' 31 | spec.add_runtime_dependency 'pry-stack_explorer', '~> 0.4', '>= 0.4.9' 32 | spec.add_runtime_dependency 'pry-remote', '~> 0.1', '>= 0.1.7' 33 | spec.add_runtime_dependency 'pry-byebug', '>= 3.1' 34 | spec.add_runtime_dependency 'hirb', '~> 0.7', '>= 0.7.3' 35 | spec.add_runtime_dependency 'railties', '>= 3.0', '< 5.0' 36 | end 37 | -------------------------------------------------------------------------------- /lib/jazz_hands2.rb: -------------------------------------------------------------------------------- 1 | require "jazz_hands2/version" 2 | require "jazz_hands2/railtie" if defined?(Rails) 3 | require 'active_support' 4 | require 'readline' 5 | 6 | module JazzHands2 7 | # Color the prompt? 8 | # 9 | # A different setting than Pry.color since some may like colored output, but a 10 | # plain prompt. 11 | # 12 | # Default: 'true' for GNU readline or rb-readline which correctly count line 13 | # widths with color codes when using \001 and \002 hints. 'false' for 14 | # libedit-based wrapper (standard on OS X unless ruby is explicitly compiled 15 | # otherwise). 16 | # 17 | mattr_accessor :colored_prompt 18 | self.colored_prompt = (Readline::VERSION !~ /EditLine/) 19 | 20 | # Separator between application name and input in the prompt. 21 | # 22 | # Default: right angle quote, or '>' when using rb-readline which doesn't 23 | # handle mixed encodings well. 24 | # 25 | mattr_accessor :prompt_separator 26 | self.prompt_separator = defined?(RbReadline) ? '>' : "\u00BB" 27 | 28 | ### Internal methods ### 29 | mattr_accessor :_hirb_output 30 | end 31 | -------------------------------------------------------------------------------- /lib/jazz_hands2/hirb_ext.rb: -------------------------------------------------------------------------------- 1 | require 'hirb' 2 | require 'pry' 3 | 4 | class << Hirb::View 5 | alias_method :enable_output_method_existing, :enable_output_method 6 | alias_method :disable_output_method_existing, :disable_output_method 7 | 8 | def enable_output_method 9 | @output_method = true 10 | JazzHands2._hirb_output = true 11 | enable_output_method_existing 12 | end 13 | 14 | def disable_output_method 15 | JazzHands2._hirb_output = false 16 | disable_output_method_existing 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /lib/jazz_hands2/railtie.rb: -------------------------------------------------------------------------------- 1 | require 'pry' 2 | require 'pry-rails' 3 | require 'pry-doc' 4 | require 'pry-git' 5 | require 'pry-remote' 6 | require 'pry-stack_explorer' 7 | require 'jazz_hands2/hirb_ext' 8 | require 'pry-byebug' 9 | 10 | module JazzHands2 11 | class Railtie < Rails::Railtie 12 | initializer 'jazz_hands2.initialize' do |app| 13 | silence_warnings do 14 | Pry.config.should_load_plugins = false 15 | 16 | # Hirb in pry 17 | Pry.config.print = -> (output, value, _pry_ = Pry) do 18 | if JazzHands2._hirb_output 19 | return if Hirb::View.view_or_page_output(value) 20 | end 21 | if defined?(AwesomePrint) 22 | pretty = value.ai(indent: 2) 23 | output.puts "=> #{pretty}" 24 | else 25 | output.puts value 26 | end 27 | end 28 | Hirb.enable 29 | 30 | color = -> { Pry.color && JazzHands2.colored_prompt } 31 | red = ->(text) { color[] ? "\001\e[0;31m\002#{text}\001\e[0m\002" : text.to_s } 32 | blue = ->(text) { color[] ? "\001\e[0;34m\002#{text}\001\e[0m\002" : text.to_s } 33 | bold = ->(text) { color[] ? "\001\e[1m\002#{text}\001\e[0m\002" : text.to_s } 34 | 35 | separator = -> { red.(JazzHands2.prompt_separator) } 36 | name = app.class.parent_name.underscore 37 | colored_name = -> { blue.(name) } 38 | 39 | line = ->(pry) { "[#{bold.(pry.input_array.size)}] " } 40 | target_string = ->(object, level) do 41 | level = 0 if level < 0 42 | unless (string = Pry.view_clip(object)) == 'main' 43 | "(#{'../' * level}#{string})" 44 | else 45 | '' 46 | end 47 | end 48 | 49 | Pry.config.prompt = [ 50 | ->(object, level, pry) do # Main prompt 51 | "#{line.(pry)}#{colored_name.()}#{target_string.(object, level)} #{separator.()} " 52 | end, 53 | ->(object, level, pry) do # Wait prompt in multiline input 54 | spaces = ' ' * ( 55 | "[#{pry.input_array.size}] ".size + # Uncolored `line.(pry)` 56 | name.size + 57 | target_string.(object, level).size 58 | ) 59 | "#{spaces} #{separator.()} " 60 | end 61 | ] 62 | end 63 | end 64 | end 65 | end 66 | -------------------------------------------------------------------------------- /lib/jazz_hands2/version.rb: -------------------------------------------------------------------------------- 1 | module JazzHands2 2 | VERSION = "1.0.2" 3 | end 4 | --------------------------------------------------------------------------------