├── .gitignore ├── .rbenv-version ├── CHANGELOG.md ├── Gemfile ├── LICENSE ├── README.md ├── Rakefile ├── jazz_hands.gemspec └── lib ├── jazz_hands.rb └── jazz_hands ├── hirb_ext.rb ├── railtie.rb └── version.rb /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | *.rbc 3 | .bundle 4 | .config 5 | .yardoc 6 | Gemfile.lock 7 | InstalledFiles 8 | _yardoc 9 | coverage 10 | doc/ 11 | lib/bundler/man 12 | pkg 13 | rdoc 14 | spec/reports 15 | test/tmp 16 | test/version_tmp 17 | tmp 18 | -------------------------------------------------------------------------------- /.rbenv-version: -------------------------------------------------------------------------------- 1 | 1.9.3-p327 2 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.5.2 (2013-10-24) 2 | 3 | * Upgrade [pry-rails][pry-rails] to the latest 0.3.2, 4 | [awesome_print][awesome_print] to 1.2 and loosen it's dependency, and removed 5 | [coderay][coderay] as an explicit dependency since [pry][pry] already includes 6 | it. 7 | 8 | ## 0.5.1 (2013-06-28) 9 | 10 | * Upgrade [pry-rails][pry-rails] to the latest 0.3.1, [pry-doc][pry-doc] 0.4.6, 11 | [coolline][coolline] 0.4.2. 12 | 13 | 14 | ## 0.5.0 (2013-03-13) 15 | 16 | * Rails 4, Ruby 2.0.0 compatibility. 17 | * Upgrade [pry][pry] to the latest 0.9.12, 18 | [pry-stack_explorer][pry-stack_explorer] 0.4.9, [pry-remote][pry-remote] 19 | 0.1.7, [pry-debugger][pry-debugger] 0.2.2, [hirb][hirb] 0.7.1, 20 | [coderay][coderay] 1.0.9. 21 | 22 | 23 | ## 0.4.0 (2012-12-27) 24 | 25 | * Add [pry-rails][pry-rails] 0.2.2 for maintained console hooks and new 26 | `show-routes`, `show-models`, and `show-middleware` commands. 27 | * Add `JazzHands.colored_prompt` and `JazzHands.prompt_separator` options. 28 | Detect readline library to turn off incompatible colored prompt or Unicode 29 | prompt separator where appropriate. Fixes #1 and #2. 30 | * Upgrade [pry][pry] to the latest 0.9.10, [pry-doc][pry-doc] 0.4.4, 31 | [pry-stack_explorer][pry-stack_explorer] 0.4.7, [pry-remote][pry-remote] 32 | 0.1.6, [pry-debugger][pry-debugger] 0.2.1, [hirb][hirb] 0.7.0, 33 | [Coolline][coolline] 0.4.0, [coderay][coderay] 1.0.8, 34 | [awesome_print][awesome_print] 1.1.0. Fixes #4. 35 | 36 | ## 0.3.1 (2012-06-11) 37 | 38 | * Upgrade [pry-debugger][pry-debugger] to 0.2.0. 39 | 40 | ## 0.3.0 (2012-06-07) 41 | 42 | * Replace [pry-nav][pry-nav] with [pry-debugger][pry-debugger] for improved 43 | performance and no segfaults. `JazzHands.enable_pry_nav` removed. 44 | * Upgrade [pry][pry] to the latest 0.9.9, [pry-doc][pry-doc] 0.4.2, 45 | [pry-git][pry-git] 0.2.3, [pry-stack_explorer][pry-stack_explorer] 0.4.2, 46 | [pry-remote][pry-remote] 0.1.4, [coderay][coderay] 1.0.6. 47 | 48 | ## 0.2.0 (2012-03-19) 49 | 50 | * Add [pry-stack_explorer][pry-stack_explorer] 0.4.1. 51 | * Upgrade [pry-remote][pry-remote] to 0.1.1 and [pry-nav][pry-nav] to 0.2.0. 52 | * Upgrade recommended gem minor versions: [pry][pry] 0.9.8.4, [pry-doc][pry-doc] 53 | 0.4.1, [hirb][hirb] 0.6.2, and [coderay][coderay] 1.0.5. 54 | 55 | ## 0.1.2 (2012-01-23) 56 | 57 | * Improved Rails 3.2 compatibility. Console methods like `app`, `new_session`, 58 | `reload!`, `helper`, and `controller` work as expected. 59 | 60 | ## 0.1.1 (2012-01-20) 61 | 62 | * Rails 3.2 compatibility 63 | 64 | ## 0.1.0 (2012-01-04) 65 | 66 | * For performance, enable [pry-nav][pry-nav] only on MRI 1.9.3 by default. To 67 | use on MRI 1.9.2, add `JazzHands.enable_pry_nav` to a Rails initializer. 68 | * Due to buggy behavior, syntax highlighting as you type via 69 | [Coolline][coolline] and [Coderay][coderay] is disabled by default. Enable 70 | with `JazzHands.enable_syntax_highlighting_as_you_type` in a Rails 71 | initializer. MRI 1.9.3 only. 72 | * Fix [Hirb][hirb] support. 73 | * Upgrade [awesome_print][awesome_print] to 1.0.2. 74 | 75 | ## 0.0.6 (2011-12-03) 76 | 77 | * Add line numbers to the prompt for easy reference when using `_in_` and 78 | `_out`. 79 | * Upgrade [pry-nav][pry-nav] to 0.0.4. 80 | 81 | 82 | ## 0.0.5 (2011-12-01) 83 | 84 | * Add [Hirb][hirb] support. Enable with `Hirb.enable` in the console. 85 | * Upgrade [pry-nav][pry-nav] to 0.0.3. 86 | 87 | 88 | ## 0.0.4 (2011-11-30) 89 | 90 | * Add explicit requires for pry plugin gems. 91 | 92 | 93 | ## 0.0.3 (2011-11-30) 94 | 95 | * Add [pry-nav][pry-nav]. 96 | * Upgrade [awesome_print][awesome_print] to 1.0.1. 97 | 98 | 99 | ## 0.0.2 (2011-11-25) 100 | 101 | * Add [pry-doc][pry-doc]. 102 | 103 | 104 | ## 0.0.1 (2011-11-25) 105 | 106 | * First release. Combine [pry][pry], [awesome_print][awesome_print], 107 | [coolline][coolline] + [coderay][coderay], [pry-remote][pry-remote], 108 | [pry-git][pry-git]. Bit of glue to replace IRB with pry in Rails console, 109 | pretty colors. 110 | 111 | 112 | [pry]: http://pry.github.com 113 | [awesome_print]: https://github.com/michaeldv/awesome_print 114 | [pry-doc]: https://github.com/pry/pry-doc 115 | [pry-git]: https://github.com/pry/pry-git 116 | [pry-nav]: https://github.com/nixme/pry-nav 117 | [pry-remote]: https://github.com/Mon-Ouie/pry-remote 118 | [coolline]: https://github.com/Mon-Ouie/coolline 119 | [coderay]: https://github.com/rubychan/coderay 120 | [hirb]: https://github.com/cldwalker/hirb 121 | [pry-stack_explorer]: https://github.com/pry/pry-stack_explorer 122 | [pry-debugger]: https://github.com/nixme/pry-debugger 123 | [pry-rails]: https://github.com/rweng/pry-rails 124 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'http://rubygems.org' 2 | 3 | gemspec 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | Copyright (C) 2011 by Gopal Patel 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Jazz Hands [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/nixme/jazz_hands/trend.png)](https://bitdeli.com/free "Bitdeli Badge") 2 | ========== 3 | 4 | Spending hours in the rails console? Spruce it up and show off those 5 | hard-working hands! 6 | 7 | **jazz_hands** is an opinionated set of console-related gems and a bit of glue: 8 | 9 | * [**Pry**][pry] for a powerful shell alternative to IRB. 10 | * [**Awesome Print**][awesome_print] for stylish pretty print. 11 | * [**Hirb**][hirb] for tabular collection output. 12 | * [**Pry Rails**][pry-rails] for additional commands (`show-routes`, 13 | `show-models`, `show-middleware`) in the Rails console. 14 | * [**Pry Doc**][pry-doc] to browse Ruby source, including C, directly from the 15 | console. 16 | * [**Pry Git**][pry-git] to teach the console about git. Diffs, blames, and 17 | commits on methods and classes, not just files. 18 | * [**Pry Remote**][pry-remote] to connect remotely to a Pry console. 19 | * [**Pry Debugger**][pry-debugger] to turn the console into a simple debugger. 20 | * [**Pry Stack Explorer**][pry-stack_explorer] to navigate the call stack and 21 | frames. 22 | * [**Coolline**][coolline] and [**Coderay**][coderay] for syntax highlighting as 23 | you type. _Optional. MRI 1.9.3/2.0.0 only_ 24 | 25 | 26 | ## Usage 27 | 28 | Ruby 1.9.2+, Rails 3 or 4 only. Add to your project Gemfile: 29 | 30 | ```ruby 31 | group :development, :test do 32 | gem 'jazz_hands' 33 | end 34 | ``` 35 | 36 | That's it. Run `rails console` as usual. 37 | 38 | [Hirb][hirb] isn't enabled by default. To use, run `Hirb.enable` in the console. 39 | 40 | Ruby compiled against a proper readline library, ideally GNU readline, is 41 | recommended. Alternatively, [`gem install rb-readline`][rb-readline] for an 42 | acceptible backup. Using ruby compiled against a `libedit` wrapper (primarily OS 43 | X) will work but is not recommended. 44 | 45 | 46 | ## Options 47 | 48 | Change the following options by creating an initializer in your Rails project 49 | Example `config/initializers/jazz_hands.rb`: 50 | 51 | ```ruby 52 | if defined?(JazzHands) 53 | JazzHands.colored_prompt = false 54 | JazzHands.enable_syntax_highlighting_as_you_type! 55 | end 56 | ``` 57 | 58 | ### `colored_prompt` 59 | 60 | Color the console prompt? Defaults to `true` when the current ruby is compiled 61 | against GNU readline or `rb-readline`, which don't have issues counting 62 | characters in colored prompts. `false` for libedit. 63 | 64 | Note: `Pry.color = false` trumps this setting and disables all console coloring. 65 | 66 | ### `prompt_separator` 67 | 68 | Separator string between the application name and line input. Defaults to `»` 69 | for GNU readline or libedit. Defaults to `>` for `rb-readline` which fails on 70 | mixed encodings. 71 | 72 | ### Syntax highlighting 73 | 74 | Syntax highlighting as you type via [Coolline][coolline] and [Coderay][coderay] 75 | is disabled by default due to slightly buggy behavior. To enable, add 76 | `JazzHands.enable_syntax_highlighting_as_you_type!` to the initializer. Only 77 | works with MRI 1.9.3 or 2.0.0. 78 | 79 | 80 | ## Contributing 81 | 82 | Patches and bug reports are welcome. Just send a [pull request][pullrequests] or 83 | file an [issue][issues]. [Project changelog][changelog]. 84 | 85 | 86 | [pry]: http://pry.github.com 87 | [awesome_print]: https://github.com/michaeldv/awesome_print 88 | [hirb]: https://github.com/cldwalker/hirb 89 | [pry-rails]: https://github.com/rweng/pry-rails 90 | [pry-doc]: https://github.com/pry/pry-doc 91 | [pry-git]: https://github.com/pry/pry-git 92 | [pry-debugger]: https://github.com/nixme/pry-debugger 93 | [pry-remote]: https://github.com/Mon-Ouie/pry-remote 94 | [pry-stack_explorer]: https://github.com/pry/pry-stack_explorer 95 | [coolline]: https://github.com/Mon-Ouie/coolline 96 | [coderay]: https://github.com/rubychan/coderay 97 | [rb-readline]: https://github.com/luislavena/rb-readline 98 | [pullrequests]: https://github.com/nixme/jazz_hands/pulls 99 | [issues]: https://github.com/nixme/jazz_hands/issues 100 | [changelog]: https://github.com/nixme/jazz_hands/blob/master/CHANGELOG.md 101 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env rake 2 | 3 | require 'bundler/gem_tasks' 4 | -------------------------------------------------------------------------------- /jazz_hands.gemspec: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | 3 | require File.expand_path('../lib/jazz_hands/version', __FILE__) 4 | 5 | Gem::Specification.new do |gem| 6 | gem.name = 'jazz_hands' 7 | gem.version = JazzHands::VERSION 8 | gem.author = 'Gopal Patel' 9 | gem.email = 'nixme@stillhope.com' 10 | gem.license = 'MIT' 11 | gem.homepage = 'https://github.com/nixme/jazz_hands' 12 | gem.summary = 'Exercise those fingers. Pry-based enhancements for the default Rails console.' 13 | gem.description = "Spending hours in the rails console? Spruce it up and show off those hard-working hands! jazz_hands replaces IRB with Pry, improves output through awesome_print, and has some other goodies up its sleeves." 14 | 15 | gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } 16 | gem.files = `git ls-files`.split("\n") 17 | gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") 18 | gem.require_paths = ['lib'] 19 | 20 | # Dependencies 21 | gem.required_ruby_version = '>= 1.9.2' 22 | gem.add_runtime_dependency 'pry', '~> 0.9.12' 23 | gem.add_runtime_dependency 'pry-rails', '~> 0.3.2' 24 | gem.add_runtime_dependency 'pry-doc', '~> 0.4.6' 25 | gem.add_runtime_dependency 'pry-git', '~> 0.2.3' 26 | gem.add_runtime_dependency 'pry-stack_explorer', '~> 0.4.9' 27 | gem.add_runtime_dependency 'pry-remote', '>= 0.1.7' 28 | gem.add_runtime_dependency 'pry-debugger', '~> 0.2.2' 29 | gem.add_runtime_dependency 'hirb', '~> 0.7.1' 30 | gem.add_runtime_dependency 'coolline', '>= 0.4.2' 31 | gem.add_runtime_dependency 'awesome_print', '~> 1.2' 32 | gem.add_runtime_dependency 'railties', '>= 3.0', '< 5.0' 33 | end 34 | -------------------------------------------------------------------------------- /lib/jazz_hands.rb: -------------------------------------------------------------------------------- 1 | require 'jazz_hands/version' 2 | require 'jazz_hands/railtie' if defined?(Rails) 3 | require 'active_support' 4 | require 'readline' 5 | 6 | module JazzHands 7 | 8 | ### Options ### 9 | 10 | # Color the prompt? 11 | # 12 | # A different setting than Pry.color since some may like colored output, but a 13 | # plain prompt. 14 | # 15 | # Default: 'true' for GNU readline or rb-readline which correctly count line 16 | # widths with color codes when using \001 and \002 hints. 'false' for 17 | # libedit-based wrapper (standard on OS X unless ruby is explicitly compiled 18 | # otherwise). 19 | # 20 | mattr_accessor :colored_prompt 21 | self.colored_prompt = (Readline::VERSION !~ /EditLine/) 22 | 23 | # Separator between application name and input in the prompt. 24 | # 25 | # Default: right angle quote, or '>' when using rb-readline which doesn't 26 | # handle mixed encodings well. 27 | # 28 | mattr_accessor :prompt_separator 29 | self.prompt_separator = defined?(RbReadline) ? '>' : "\u00BB" 30 | 31 | 32 | class << self 33 | # Enable syntax highlighting as you type in the Rails console via coolline and 34 | # coderay (MRI 1.9.3+ only). Disabled by default as it's a bit buggy. 35 | # 36 | # Call from a Rails initializer: 37 | # 38 | # JazzHands.enable_syntax_highlighting_as_you_type! 39 | # 40 | def enable_syntax_highlighting_as_you_type! 41 | raise 'Syntax highlighting only supported on 1.9.3+' unless RUBY_VERSION >= '1.9.3' 42 | 43 | # Use coolline with CodeRay for syntax highlighting as you type. 44 | # Only works on >= 1.9.3 because coolline depends on io/console. 45 | 46 | require 'coolline' 47 | require 'coderay' 48 | 49 | Pry.config.input = Coolline.new do |c| 50 | c.transform_proc = proc do 51 | CodeRay.scan(c.line, :ruby).term 52 | end 53 | 54 | c.completion_proc = proc do 55 | word = c.completed_word 56 | Object.constants.map(&:to_s).select { |w| w.start_with? word } 57 | end 58 | end 59 | end 60 | alias :enable_syntax_highlighting_as_you_type :enable_syntax_highlighting_as_you_type! 61 | end 62 | 63 | ### Internal methods ### 64 | 65 | mattr_accessor :_hirb_output 66 | end 67 | -------------------------------------------------------------------------------- /lib/jazz_hands/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 | JazzHands._hirb_output = true 11 | enable_output_method_existing 12 | end 13 | 14 | def disable_output_method 15 | JazzHands._hirb_output = false 16 | disable_output_method_existing 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /lib/jazz_hands/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 'awesome_print' 8 | require 'jazz_hands/hirb_ext' 9 | require 'pry-debugger' 10 | 11 | 12 | module JazzHands 13 | class Railtie < Rails::Railtie 14 | initializer 'jazz_hands.initialize' do |app| 15 | silence_warnings do 16 | # We're managing the loading of plugins. So don't let pry autoload them. 17 | Pry.config.should_load_plugins = false 18 | 19 | # Use awesome_print for output, but keep pry's pager. If Hirb is 20 | # enabled, try printing with it first. 21 | Pry.config.print = ->(output, value) do 22 | return if JazzHands._hirb_output && Hirb::View.view_or_page_output(value) 23 | pretty = value.ai(indent: 2) 24 | Pry::Helpers::BaseHelpers.stagger_output("=> #{pretty}", output) 25 | end 26 | 27 | # Friendlier prompt - line number, app name, nesting levels look like 28 | # directory paths. 29 | # 30 | # Heavy use of lazy lambdas so configuration (like Pry.color) can be 31 | # changed later or even during console usage. 32 | # 33 | # Custom color helpers using hints \001 and \002 so that good readline 34 | # libraries (GNU, rb-readline) correctly ignore color codes when 35 | # calculating line length. 36 | 37 | color = -> { Pry.color && JazzHands.colored_prompt } 38 | red = ->(text) { color[] ? "\001\e[0;31m\002#{text}\001\e[0m\002" : text.to_s } 39 | blue = ->(text) { color[] ? "\001\e[0;34m\002#{text}\001\e[0m\002" : text.to_s } 40 | bold = ->(text) { color[] ? "\001\e[1m\002#{text}\001\e[0m\002" : text.to_s } 41 | 42 | separator = -> { red.(JazzHands.prompt_separator) } 43 | name = app.class.parent_name.underscore 44 | colored_name = -> { blue.(name) } 45 | 46 | line = ->(pry) { "[#{bold.(pry.input_array.size)}] " } 47 | target_string = ->(object, level) do 48 | level = 0 if level < 0 49 | unless (string = Pry.view_clip(object)) == 'main' 50 | "(#{'../' * level}#{string})" 51 | else 52 | '' 53 | end 54 | end 55 | 56 | Pry.config.prompt = [ 57 | ->(object, level, pry) do # Main prompt 58 | "#{line.(pry)}#{colored_name.()}#{target_string.(object, level)} #{separator.()} " 59 | end, 60 | ->(object, level, pry) do # Wait prompt in multiline input 61 | spaces = ' ' * ( 62 | "[#{pry.input_array.size}] ".size + # Uncolored `line.(pry)` 63 | name.size + 64 | target_string.(object, level).size 65 | ) 66 | "#{spaces} #{separator.()} " 67 | end 68 | ] 69 | end 70 | end 71 | end 72 | end 73 | -------------------------------------------------------------------------------- /lib/jazz_hands/version.rb: -------------------------------------------------------------------------------- 1 | module JazzHands 2 | VERSION = '0.5.2' 3 | end 4 | --------------------------------------------------------------------------------