• Stars
    star
    233
  • Rank 172,230 (Top 4 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 15 years ago
  • Updated almost 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Mission: Easy custom autocompletion for arguments, methods and beyond. Accomplished for irb and any other readline-like console environments.

Description¶ ↑

Bond is on a mission to improve autocompletion in ruby, especially for irb/ripl. Aside from doing everything irb’s can do and fixing its quirks, Bond can autocomplete argument(s) to methods, uniquely completing per module, per method and per argument. Bond brings ruby autocompletion closer to bash/zsh as it provides a configuration system and a DSL for creating custom completions and completion rules. With this configuration system, users can customize their autocompletions and share it with others. Bond can also load completions that ship with gems. Bond is able to offer more than irb’s completion since it uses the full line of input when completing as opposed to irb’s last-word approach.

Install¶ ↑

Note: Bond is only supported on platforms with make e.g. OSX, Linux and Cygwin Windows. Once 1.8 support is dropped this won’t be an issue.

To use bond with Readline (version >= 5.6 recommended) or JLine for JRuby users, install the gem with:

gem install bond

To use bond with a pure ruby readline i.e. Windows users or users without Readline:

gem install bond rb-readline -- --without-readline

To use bond without readline support (and presumably use your own readline plugin):

gem install bond -- --without-readline

Setup¶ ↑

If you’re using ripl instead of irb, bond is already setup.

To start off, replace irb’s completion (require ‘irb/completion’) with Bond’s enhanced version in your irbrc:

require 'bond'
Bond.start
# For users using a pure ruby readline
Bond.start :readline => :ruby

This setup gives you more consistent method completion on any object, customizable completions and argument completion of some 80+ methods including Hash#[], Kernel#system, Kernel#require and some Rails methods.

Method Argument Completion¶ ↑

By default, Bond autocompletes arguments for a number of core methods:

$ ripl
# require completes gems and anything in $LOAD_PATH
>> require 'rb[TAB]
rbconfig.rb          rbconfig/
>> require 'rbconfig
>> require 'rbconfig.rb'

# hash methods can complete their keys
>> CONFIG::CONFIG[TAB]
>> CONFIG::CONFIG['m[TAB]
>> CONFIG::CONFIG['mandir'
>> CONFIG::CONFIG['mandir']

>> ENV['CO[TAB]
COLUMNS       COMMAND_MODE
>> ENV['COL[TAB]
>> ENV['COLUMNS'
>> ENV['COLUMNS']

# array methods can complete their elements
>> %w{ab bc cd de}.delete '[TAB]
ab  bc  cd  de
>> %w{ab  bc  cd  de}.delete 'a[TAB]
>> %w{ab  bc  cd  de}.delete 'ab'

# system can complete shell commands
>> system 'ec[TAB]
>> system 'echo
>> system 'echo'

Bond also comes with some basic Rails completions, mostly for attributes/columns of models:

$ script/console
>> Url.column_names
=> ["id", "name", "description", "created_at", "updated_at"]
>> Url.create :n[TAB]
>> Url.create :name
...
>> Url.first.update_attribute :d[TAB]
>> Url.first.update_attribute :description
...

To see more methods whose arguments can be completed:

>> puts Bond.list_methods
ActiveRecord::Base#[]
ActiveRecord::Base#attribute_for_inspect
...

Multiple Arguments¶ ↑

Every time a comma appears after a method, Bond starts a new completion. This allows a method to complete multiple arguments. Each argument can be have a unique set of completions since a completion action is aware of what argument it is currently completing. Take for example the completion for Object#send:

>> Bond.send :me[TAB]
>> Bond.send :method
>> Bond.send :method, [TAB]
agent       complete    config      recomplete  spy         start
>> Bond.send :method, :a[TAB]
>> Bond.send :method, :agent
=> #<Method: Module#agent>

Notice the arguments were completed differently: the first completing for Bond.send and the second for Bond.method. The second argument was only able to complete because there’s a completion for Module#method. Using Object#send it’s possible to use completions defined for private methods i.e. Module#remove_const:

>> Bond.send :remove_const, :A[TAB]
:Agent            :AnywhereMission
>> Bond.send :remove_const, :Ag[TAB]
>> Bond.send :remove_const, :Agent

Since Bond uses a comma to delimit completions, methods whose last argument is a hash can have their hash keys autocompleted. Revisiting the above Rails example:

>> Url.create :n[TAB]
>> Url.create :name
>> Url.create :name=>'example.com', :d[TAB]
>> Url.create :name=>'example.com', :description
...
>> Url.first.update_attributes :d[TAB]
>> Url.first.update_attributes :description
>> Url.first.update_attributes :description=>'zzz', :u[TAB]
>> Url.first.update_attributes :description=>'zzz', :updated_at
...

Creating Completions¶ ↑

Bond’s completion resembles bash/zsh’s. When Bond.start is called, Bond looks up completion files in multiple places: ~/.bondrc and ~/.bond/completions/*.rb. Here’s how bash and bond completion definitions compare in their config files:

# Bash
complete -W "one two three" example
complete -F _example example

# Bond
complete(:method=>'example') { %w{one two three} }
complete(:method=>'example', :action=>'_example')

To read up on the wealth of completion types one can make, see the docs for Bond.complete.

Creating Argument Completions for Methods¶ ↑

While the above method completion was a static list, most completions will dynamically generate completions based on the method’s receiver (object). Let’s look at such an example with Hash#[] :

complete(:method=>"Hash#[]") {|e| e.object.keys }

As you can see, the currently typed object is available as the :object attribute of the block’s argument, a Bond::Input object. This object can offer other useful attributes describing what the user has typed. For example, the :argument attribute holds the current argument number being completed. Here’s a completion that uses this attribute to complete differently for the first argument and remaining arguments:

complete(:method=>'example') {|e| e.argument > 1 ? %w{verbose force noop} : %w{one two three} }

Creating Other Completions¶ ↑

First you should know Bond works: A user creates completion missions with Bond.start and its config files (which are just Bond.complete calls). When a user autocompletes, Bond.agent looks up missions in the order they were defined and completes with the first one that matches. The exception to this ordering are :method completions.

To create a completion, Bond.complete needs a regexp to match the user input and an action to generate completions when it matches. If the completion isn’t working, use Bond.spy to see which completion is executing. If a completion needs to be placed before existing completions, use the :place option.

Irb’s Incorrect Completions¶ ↑

There are a number of incorrect completions irb gives for object methods. Bond fixes all of the ones described below.

Irb completes anything surrounded with ‘{}’ the same:

$ irb
>> proc {}.c[TAB]
}.call     }.class    }.clear    }.clone    }.collect
>> %w{ab bc}.c[TAB]
}.call     }.class    }.clear    }.clone    }.collect
>> %r{ab bc}.c[TAB]
}.call     }.class    }.clear    }.clone    }.collect
>> {}.c[TAB]
}.call     }.class    }.clear    }.clone    }.collect
>> {}.call
NoMethodError: undefined method `call' for {}:Hash
        from (irb):1

There are a number of cases where irb gives a default completion because it doesn’t know what else to do.

 # The default completion
 >> self.[TAB]
 Display all 496 possibilities? (y or n)

 # And all of these cases are apparently the same:
 >> nil.[TAB]
 Display all 496 possibilities? (y or n)
 >> false.[TAB]
 Display all 496 possibilities? (y or n)
 >> true.[TAB]
 Display all 496 possibilities? (y or n)
 # Regular expressions with spaces
 >> /man oh man/.[TAB]
 Display all 496 possibilities? (y or n)
 # Grouped expressions
>> (3 + 4).[TAB]
Display all 496 possibilities? (y or n)

# Nested hashes and arrays
>> {:a=>{:a=>1}}.[TAB]
Display all 496 possibilities? (y or n)
>> [[1,2], [3,4]].[TAB]
Display all 496 possibilities? (y or n)

# Any object produced from a method call
>> 'awesome'.to_sym.[TAB]
Display all 496 possibilities? (y or n)
>> :dude.to_s.[TAB]
Display all 496 possibilities? (y or n)

Ranges don’t get much love

>> (2..4).[TAB]
# Nothing happens

Limitations¶ ↑

If on a Mac and using Editline as a Readline replacement (Readline::VERSION =~ /editline/i), Bond will probably not work consistently. I strongly recommend switching to the official Readline. If using rvm, this post has good instructions for reinstalling ruby with the official Readline.

Credits¶ ↑

  • Csaba Hank for providing the C extension which Bond uses to read Readline’s full buffer.

  • Takao Kouji for commiting this Readline enhancement to ruby 1.9.2.

  • pd for compatibility with emacs’ inf-ruby mode.

  • timcharper for improving extconf.rb.

  • headius and rking for jruby help

  • ConradIrwin for 2.0 and other fixes

  • tobias for a java version of the gem

  • havenwood for 2.1 fixes

  • yui-knk, rev112 and dre-hh for bug fixes.

Bugs/Issues¶ ↑

Please report them on github.

Contributing¶ ↑

See here

Todo¶ ↑

  • Make completion actions more synonymous with argument types.

  • Cache expensive completion actions.

  • Ensure completions work when there is additional, unrelated text to the right of a completion.

More Repositories

1

hirb

A mini view framework for console/irb that's easy to use, even while under its influence. Console goodies include a no-wrap table, auto-pager, tree and menu.
Ruby
1,637
star
2

ripl

ruby interactive print loop - A light, modular alternative to irb
Ruby
395
star
3

tux

Sinatra dressed for interactive ruby - a sinatra shell
Ruby
301
star
4

boson

A command/task framework similar to rake and thor built with extendability in mind.
Ruby
218
star
5

one9

commandline tool to convert 1.8 code to ruby 1.9.2. So what's your excuse for not upgrading to 1.9.2? ;)
Ruby
171
star
6

logseq-query

Clojure
159
star
7

vimdb

vim knowledge tabularized - search vim keys, options and more with great precision.
Ruby
157
star
8

table

Display ascii tables for almost any data structure with ease.
Clojure
107
star
9

lightning

Speed for your shell and the commandline
Ruby
74
star
10

bahia

commandline acceptance testing - aruba for non-cucumber test frameworks
Ruby
52
star
11

nirvana

A ruby web shell that is very ape and very nice
JavaScript
52
star
12

datomic-free

A wrapper around datomic-free to easily start and upgrade it
Shell
51
star
13

irbfiles

ripl/irb the way I like it (enhanced with boson)
Ruby
50
star
14

datomico

Use datomic with intention revealing names. Ease of use and sticking to datomic's principles are encouraged.
Clojure
49
star
15

bb-clis

Babashka CLIs
Clojure
48
star
16

has_machine_tags

A rails tagging gem implementing flickr's machine tags + maybe more (semantic tags)
Ruby
44
star
17

debugger-completion

Mission: auto-complete debugger
Ruby
43
star
18

datomic-client

ruby client for datomic's http api
Ruby
41
star
19

tag-tree

Explores the wicked combo of machine tag queries + their results as trees.
Ruby
28
star
20

alias

Creates, manages and saves aliases for class methods, instance methods, constants, delegated methods and more.
Ruby
25
star
21

console_update

A gem to edit your database records via the console and your favorite editor.
Ruby
21
star
22

ltfiles

my light table dotfiles
JavaScript
20
star
23

gem_grep

*Not being maintained. Any takers?* A gem command plugin which enhances the search command by providing extra search options and displaying results as a table.
Ruby
17
star
24

machinetag.js

jQuery plugins to search/parse machine tags and display machine tag trees.
JavaScript
16
star
25

dotfiles

config files for my most used apps
Shell
15
star
26

rubydoc

A repl tool to help rubyists find clojure equivalents
Clojure
15
star
27

wolf

Devour computational knowledge on the commandline with wolframalpha
Ruby
14
star
28

ripl-play

A ripl plugin to playback and record inputs in ripl
Ruby
14
star
29

logseq-config

13
star
30

ripl-rails

alternative to script/console using ripl
Ruby
11
star
31

dlint

Lint datomic-style datalog queries and rules. For clojure and clojurescript
Clojure
11
star
32

osx-setup

Set up my osx environment with a one-liner
Ruby
11
star
33

Mermaid

Light Table plugin that generates diagrams and flowcharts from text using mermaid
JavaScript
11
star
34

datomic-box

[wip] Spin up a running Datomic Free box from the commandline. Done.
Clojure
10
star
35

rbenv-travis

Run travis tests locally using rbenv rubies
Ruby
10
star
36

local_gem

Load/require any gem/library simply given its path. Great for nascent gems or for trying the latest code on a gem.
Ruby
10
star
37

lein-spell

Catch spelling mistakes in programming documents and clojure docstrings.
Clojure
9
star
38

gitbeam

Light Table plugin for seamless github interaction
JavaScript
9
star
39

sacha

An outliner for Light Table
JavaScript
9
star
40

photon

Light Table plugin to quickly open your most active projects
Clojure
9
star
41

gh-active-issues

A pedestal service that helps github maintainers grapple with their issues and helps users understand what's before their issue
Clojure
8
star
42

Sancho

Your trusty Clojure(Script) sidekick for LightTable. Includes grimoire and crossclj integration
JavaScript
8
star
43

Share

Collaborative editing for Light Table
JavaScript
7
star
44

nbb-clis

Nbb CLIs
Clojure
7
star
45

leinfiles

Handy functions for a clojure repl - most likely lein repl
Clojure
7
star
46

boson-more

Home for boson2 plugins
Ruby
7
star
47

queriac

Picking up where Yubnub left off..
Ruby
6
star
48

ripl-rack

script/console for rack using ripl
Ruby
6
star
49

ripl-em

interact with eventmachine code - asynchronously of course
Ruby
6
star
50

ripl-irb

A ripl plugin to smooth the transition from irb
Ruby
6
star
51

rbenv-plugin

Manage rbenv plugins
Ruby
6
star
52

tag

tag anything from the commandline
Ruby
6
star
53

ripl-commands

This ripl plugin adds commands to ripl that are similar to irb's
Ruby
6
star
54

ripl-hijack

hijack a ruby process a la ripl
Ruby
5
star
55

ripl-johnson

A full-featured javascript shell using johnson (mozilla's tracemonkey)
Ruby
5
star
56

ripl-i18n

A ripl plugin that let's ripl speak your language
Ruby
4
star
57

repl.js

jquery plugin to replify an html element
JavaScript
4
star
58

previewradio-pedestal

a sinatra to pedestal-service comparison
Clojure
4
star
59

sinatra-bootstrap

sinatra app bootstrapped by bootstrap and some
JavaScript
4
star
60

ripl-misc

some misc ripl plugin ideas
Ruby
4
star
61

ripl-color_error

ripl plugin to colorize errors
Ruby
4
star
62

lein-grep

A Leiningen plugin that renders meaningful search results.
Clojure
4
star
63

urls

easy bookmarking for the commandline and beyond
Ruby
4
star
64

bond-yard

bond plugin to generate completions for yard-documented methods
Ruby
3
star
65

fda-events

Exploratory app for FDA's drug adverse event API
Clojure
3
star
66

core

*Unfinished* Easily use and share your ruby extensions and other extension libraries ie ActiveSupport, facets
Ruby
3
star
67

lein-open

Open a jar in an editor easily
Clojure
3
star
68

emoji

middleware/interceptorware to add bundled emoji images
Clojure
3
star
69

github-contributions

App to show a github user's forks and contributions to each one. Using pedestal and SSE
Clojure
3
star
70

jrepl

*Work in progress* javascript shell with readline and autocompletion
JavaScript
3
star
71

bacon-bits

Making bacon a little tastier
Ruby
3
star
72

smart-ignore

LT plugin that auto-updates ignore-pattern based on current directories in a workspace
JavaScript
3
star
73

github_user_page.js

*broken with new layout* jquery plugin/ github bookmarklet to enhance github's user pages
JavaScript
3
star
74

emojinator

a silly app that slurps a url and emojinates any word that matches an emoji name
Clojure
2
star
75

sse-chat

simple sse chat example for pedestal, ported from sinatra
Clojure
2
star
76

ripl-debug

A ripl plugin that automatically passes a failed eval to ruby-debug
Ruby
2
star
77

bolt

[work in progress] - web commands a la queriac, done all clientside with rum/reactjs
Clojure
2
star
78

menu

More choices with less typing
Ruby
2
star
79

ripl-after_rc

A ripl plugin that defines blocks to run after ~/.irbrc
Ruby
2
star
80

logseq-clis

CLIs for logseq using nbb-logseq
Clojure
2
star
81

bacon-rr

rr adapter for bacon
Ruby
2
star
82

om-components

A collection of reusable om components [WIP]
Clojure
2
star
83

bender

smack-talking hubot
CoffeeScript
2
star
84

vimfiles

no horses were harmed while horsing around with this vim setup
Vim Script
2
star
85

websh

A sinatra web shell using ripl that deploys on Heroku.
JavaScript
2
star
86

robolot

your faithful async knight
Ruby
1
star
87

emacs.d

An emacs config based on emacs-starter-kit - optimized for ruby and clojure.
Emacs Lisp
1
star
88

ripl-ripper

ripl plugin for a multi-line ripl using ripper
Ruby
1
star
89

pedestal-dataflow-logger

An experiment in logging pedestal-app dataflow internals
Clojure
1
star
90

urls-web

web interface to urls
JavaScript
1
star
91

atomfiles

JavaScript
1
star
92

semtag.me

pedestal app that communicates via clojure data using CORS requests
Clojure
1
star
93

rip-licious

A tasty collection of rip plugins
Ruby
1
star
94

rip-ext

Rip plugin to easily synchronize gem environments across ruby versions
Ruby
1
star
95

psycho

Going psycho with syck to psych conversions? Let psycho handle this syck-psych-o-ness!
Ruby
1
star
96

is_it_ec2

is it ec2?
JavaScript
1
star
97

readline.js

jquery plugin to bring readline to the hoi polloi
JavaScript
1
star
98

migration_sql

Generate migration sql for Rails apps and Sequel
Ruby
1
star
99

link-checker

A multi-threaded link-checker powered by pedestal and SSE
Clojure
1
star
100

git-puns

Atom package to git some git laughs
Clojure
1
star