forked from tpope/pry-editline
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a903b4f
Showing
7 changed files
with
206 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/.bundle | ||
/Gemfile.lock | ||
/pkg/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
source "http://rubygems.org" | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Copyright (c) Tim Pope | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
pry-editline | ||
------------ | ||
|
||
Whenever I'm using IRB or [Pry][], my editor always feels too far away. | ||
Yes, there are [various gems](http://utilitybelt.rubyforge.org/) out | ||
there that will let me spawn an editor and evaluate the result, but | ||
that's not what I need. Usually I'm about 80 characters or so into a | ||
hairy one-liner when I think, "you know, I really wish I was in Vim | ||
right about now." In Bash, one can load the current command line into | ||
an editor with `C-x C-e`. And now, you can do so in IRB and Pry. | ||
|
||
The gem is named after [Pry][] so that it will be automatically loaded | ||
as a Pry plugin (and because, let's face it, that's a good train to | ||
hitch our wagon to). But it also works in IRB if you add `require | ||
'pry-editline'` to your `.irbrc`. | ||
|
||
[Pry]: http://pry.github.com/ | ||
|
||
FAQ | ||
--- | ||
|
||
> `C-x C-e` is too hard to type. | ||
You can add an alias for it in `~/.inputrc`. Observe: | ||
|
||
$if Ruby | ||
"\C-o": "\C-x\C-e" | ||
$endif | ||
|
||
Actually, I already added `C-o` for you. So don't add that one. It | ||
already works. It stands for "open". | ||
|
||
> It's not working on OS X. | ||
By default, readline on OS X uses libedit. I don't know what that means | ||
exactly other than it leaves you with a horribly crippled readline that | ||
doesn't work with pry-editline. To link against a different readline, | ||
pass the `--with-readline-dir=` flag to `./configure`. If you're using | ||
RVM, pass it to `rvm install`. Or better yet, make it the default: | ||
|
||
echo rvm_configure_flags=--with-readline-dir=/usr/local >> ~/.rvmrc | ||
|
||
To *install* a readline to `/usr/local`, you might consider using | ||
Homebrew. After installing, you need instruct it to link that readline | ||
into `/usr/local`: | ||
|
||
brew install readline | ||
brew link readline | ||
|
||
Actually for me, it went more like: | ||
|
||
$ brew install readline | ||
... | ||
$ brew link readline | ||
Error: readline has multiple installed versions | ||
$ brew link readline 6.2.1 | ||
Error: readline has multiple installed versions | ||
$ brew link readline -v6.2.1 | ||
Error: readline has multiple installed versions | ||
$ brew link -v6.2.1 readline | ||
Error: readline has multiple installed versions | ||
$ brew remove readline | ||
Error: readline has multiple installed versions | ||
Use `brew remove --force readline` to remove all versions. | ||
$ brew remove -v6.1 readline | ||
Error: readline has multiple installed versions | ||
Use `brew remove --force readline` to remove all versions. | ||
$ brew remove --force readline | ||
Uninstalling readline... | ||
$ brew install readline | ||
... | ||
$ brew link readline | ||
|
||
Yeah, it's a bit of a pain. Sorry your OS hates you. :( | ||
|
||
> It's not working with `rails console`/my Bundler setup. | ||
[Here's one potential workaround][workaround]. You might have to | ||
explicitly `require 'pry-editline'` in your `.pryrc`, too. | ||
|
||
[workaround]: https://github.com/carlhuda/bundler/issues/183#issuecomment-1149953 | ||
|
||
> How does it work? | ||
Well first, it overrides `ENV['INPUTRC']` so it can do some magic. And | ||
then, it does some magic! | ||
|
||
License | ||
------- | ||
|
||
Copyright (c) Tim Pope. MIT License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require "bundler/gem_tasks" | ||
task :default => :build | ||
|
||
include_path = "-I#{File.expand_path('../lib', __FILE__)}" | ||
|
||
task :pry do | ||
exec 'pry', include_path, '-rpry-editline' | ||
end | ||
|
||
task :irb do | ||
exec 'irb', include_path, '-rpry-editline' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
module PryEditline | ||
|
||
def self.editor | ||
if defined?(Pry) | ||
Pry.editor | ||
else | ||
ENV.values_at('VISUAL', 'EDITOR').compact.first || 'vi' | ||
end | ||
end | ||
|
||
def self.hijack_inputrc | ||
inputrc = [ | ||
ENV['INPUTRC'], | ||
(File.expand_path('~/.inputrc') rescue nil), | ||
'/etc/inputrc' | ||
].compact.detect { |x| File.exist?(x) } | ||
|
||
require 'tempfile' | ||
file = Tempfile.new('inputrc') | ||
file.puts '"\C-x\C-l": redraw-current-line' | ||
file.puts '"\C-x\C-e": " \C-a\t\C-k\C-x\C-l"' | ||
file.puts '"\C-o": " \C-a\t\C-k\C-x\C-l"' | ||
file.puts "$include #{inputrc}" if inputrc | ||
file.close | ||
ENV['INPUTRC'] = file.path | ||
end | ||
|
||
def self.completion_proc | ||
lambda do |s| | ||
if Readline.point == 0 && Readline.line_buffer =~ / $/ | ||
require 'tempfile' | ||
Tempfile.open(['readline-','.rb']) do |f| | ||
f.puts(Readline.line_buffer[0..-3]) | ||
f.close | ||
system("#{editor} #{f.path}") | ||
File.read(f.path).chomp | ||
end | ||
else | ||
yield s | ||
end | ||
end | ||
end | ||
|
||
end | ||
|
||
if defined?(Pry::InputCompleter) | ||
PryEditline.hijack_inputrc | ||
class <<Pry::InputCompleter | ||
unless method_defined?(:build_completion_proc_without_edit) | ||
alias build_completion_proc_without_edit build_completion_proc | ||
|
||
def build_completion_proc(*args) | ||
PryEditline.completion_proc(&build_completion_proc_without_edit(*args)) | ||
end | ||
end | ||
end | ||
elsif defined?(IRB) && defined?(Readline) | ||
PryEditline.hijack_inputrc | ||
Readline.completion_proc = PryEditline.completion_proc(&Readline.completion_proc) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# -*- encoding: utf-8 -*- | ||
$:.push File.expand_path("../lib", __FILE__) | ||
|
||
Gem::Specification.new do |s| | ||
s.name = 'pry-editline' | ||
s.version = '1.0.0' | ||
s.authors = ['Tim Pope'] | ||
s.email = ["ruby@tpop"+'e.org'] | ||
s.homepage = 'https://github.com/tpope/pry-editline' | ||
s.summary = 'C-x C-e to invoke an editor on the current pry (or irb) line' | ||
|
||
s.files = `git ls-files`.split("\n") | ||
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") | ||
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) } | ||
s.require_paths = ['lib'] | ||
|
||
s.add_development_dependency 'rake' | ||
end |