GithubHelp home page GithubHelp logo

lightning's Introduction

Description

Lightning is a commandline framework that lets users wrap commands with shell functions that are able to refer to any filesystem path by its basename. To achieve this, a group of paths to be translated are defined with shell globs. These shell globs, known as a lightning bolt, are then applied to commands to produce functions. In addition to translating basenames to full paths, lightning functions can autocomplete these basenames, resolve conflicts if they have the same name, leave any non-basename arguments untouched, and autocomplete directories above and below a basename. To make bolts shareable between users and functions easier to create, lightning has generators. A generator generates filesystem-specific globs for a bolt. Lightning comes with some default generators. Users can make their own generators with generator plugins placed under ~/.lightning/generators/.

Intro

Lightning generates shell functions which can interpret paths by their basenames. So instead of carpal-typing

$ less /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/irb.rb

just type

$ less-ruby irb.rb

less-ruby is a lightning function which wraps ‘less` with the ability to refer to system ruby files by their basenames. Being a lightning function, it can also autocomplete system ruby files:

# 1112 available system ruby files
$ less-ruby [TAB]
Display all 1112 possibilities? (y or n)

$ less-ruby a[TAB]
abbrev.rb                  abstract.rb                abstract_index_builder.rb
$ less-ruby abb[TAB]
$ less-ruby abbrev.rb
# Pages /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/abbrev.rb ...

# Autocompletion works regardless of the number of arguments
$ less-ruby -I abbrev.rb y[TAB]
yaml.rb      yamlnode.rb  ypath.rb
$ less-ruby -I abbrev.rb yp[TAB]
$ less-ruby -I abbrev.rb ypath.rb
# Pages /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/abbrev.rb and
  /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/yaml/ypath.rb ...

And here’s the one-liner that creates this function:

$ lightning function create less ruby && lightning-reload

Install

Install with rubygems:

$ gem install lightning
$ gem install yard # if you want lightning's documentation generated correctly

If you’ve installed with rubygems and ‘time lightning` takes longer than 0.05 seconds, I *strongly recommend* installing with ruby 1.9.3. Your startup time directly effects your autocompletion speed with lightning.

Once lightning is installed, we need to do a one-time setup:

# To see available install options
$ lightning install -h

# Installs lightning's core files and sources the needed lightning functions
$ lightning install && source ~/.lightning/functions.sh
Created ~/.lightningrc
Created ~/.lightning/functions.sh

# To have lightning's functionality loaded when your shell starts up
echo source ~/.lightning/functions.sh >> ~/.bashrc
# or for zsh
echo source ~/.lightning/functions.sh >> ~/.zshrc

To install and view lightning’s man page:

# If installed with rip, man pages are automatically installed
$ man lightning

# If installed with rubygems
$ gem install gem-man
$ gem man lightning

Bugs/Issues

Please report them on github.

Limitations

  • Completions that are a directory above or below a basename don’t work for zsh.

  • Only bash and zsh shells are supported. Patches are welcome to support other shells.

Credits

Todo

  • Possible aliasing of paths per function, bolt or global

  • Possible irb builder using bond

lightning's People

Contributors

cldwalker avatar ljsc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

ljsc zhando

lightning's Issues

lightning chokes on some encodings

my system:

a /$ uname -srv
Linux 2.6.33-ARCH #1 SMP PREEMPT Mon Apr 5 05:57:38 UTC 2010
a ~$ locale
LANG=en_GB.UTF-8
a /$ ruby --version
ruby 1.9.1p378 (2010-01-10 revision 26273) [i686-linux]

steps to reproduce the bug:

mkdir lightning_unicode_test
cd lightning_unicode_test
touch ä
echo-wild [press tab]

result on my machine:

a ~/lightning_unicode_test$ echo-wild /usr/lib/ruby/1.9.1/shellwords.rb:80: warning: regexp match /.../n against to UTF-8 string
/usr/lib/ruby/1.9.1/shellwords.rb:80: warning: regexp match /.../n against to UTF-8 string
/usr/lib/ruby/1.9.1/shellwords.rb:80: warning: regexp match /.../n against to UTF-8 string

Non-filesystem based completions

Is it possible to use non-filesystem based completions, e.g. remote svn paths? Can i provide custom command for "item" list generation?

[feature] Use ENV vars in bolt globs

Would be nice to be able to use environment variables like $HOME, $rvm_path, $GEM_HOME, $RUBYLIB, etc. Could be extended to have fully dynamic paths, like a glob that searches all of $GEM_PATH (which would need to be split on colon).

Of course, since it's Ruby, these could be strings like #{ENV['HOME']} as an alternative to the shell-style syntax.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.