Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Lots of plumbing.

  • Loading branch information...
commit bc138857133a0916e151889c59ee5b1e2e0f260e 1 parent 6458432
Victor Hugo Borja authored
2  Gemfile
View
@@ -0,0 +1,2 @@
+source :rubygems
+gem 'command-t'
10 Gemfile.lock
View
@@ -0,0 +1,10 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ command-t (1.0.1)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ command-t
24 LICENSE
View
@@ -0,0 +1,24 @@
+Copyright (c) 2011, Victor Hugo Borja <vic.borja@gmail.com>
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of the <organization> nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56 README.md
View
@@ -1,18 +1,58 @@
Mr T
====
-Textmate-like file finder on a curses interface. Intended for file completion on
-shell prompt.
+What is it.
+-----------
-Mr T requires a ruby compiled with curses devel, it also makes use of the ruby
-extension provided by (Command-T)[https://wincent.com/products/command-t]
+Mr T is a curses based file finder. If you're familiar with Textmate's cmd-t or
+Vim's Command-T plugin, you'll feel right at home.
+Mr T allows you to have fast, file completion from your shell prompt. You can
+use it as-is by invoking the _mrT_ command, or use it as your default file
+completion strategy for some unix commands.
-== Basic Usage
- mrT [basedir]
+Requirements
+------------
-== TODO
+Mr T requires a ruby compiled with the standard curses library (you need to have
+curses-devel installed at ruby configuration time), it also makes use of the ruby
+extension provided by [Command-T][http://wincent.com/products/command-t]
+
+
+Installation
+------------
+
+rake install
+
+
+
+Usage
+-----
+
+After installation, you might be able to use the _mrT_ binary, right now it
+takes an optional directory as only argument.
+
+ mrT
+
+
+Future
+------
+
+Use Command-T caching features, expose Command-T options as command line flags.
+
+
+Contribute
+----------
+
+Feel free to adapt mrT to your needs, report any issue or send pull requests
+to the github repository:
+
+ http://github.com/vic/mrT
+
+Authors
+-------
+
+Victor Hugo Borja <vic.borja@gmail.com>
-Instructions on how to setup as bash file completion mechanism.
10 Rakefile
View
@@ -0,0 +1,10 @@
+task :gem do
+ sh 'gem build mrT.gemspec'
+end
+
+task :install => :gem do
+ v = `git describe --abbrev=0`.chomp
+ sh "gem install mrT-#{v}.gem"
+end
+
+task :default => :install
146 bin/mrT
View
@@ -1,141 +1,15 @@
#!/usr/bin/env ruby
-# TODO: make command-t a reusable gem!
-$LOAD_PATH.unshift File.expand_path('~/.vim/bundle/command-t/ruby')
-
-require 'curses'
-require 'command-t/finder'
-
-class BashT
-
- attr_reader :str, :shown_from, :pwd
-
- def initialize(pwd)
- @str = []
- @options = {
- }
- @pwd = pwd
- @finder = CommandT::Finder.new @pwd, @options
- end
-
- def run
- value = with_curses { interact }
- File.expand_path(value, @pwd) if value
- end
-
- def with_curses
- Curses.init_screen
- Curses.nonl
- Curses.cbreak
- Curses.noecho
-
- @screen = Curses.stdscr
- @screen.scrollok true
- @screen.keypad true
-
- begin
- value = yield
- rescue Interrupt
- Curses.close_screen
- ensure
- Curses.close_screen
- end
- end
-
- def interact
- catch :done do
- filter
- while true
- Curses.setpos(0,0)
- @screen.clrtoeol
- Curses.addstr('>> ')
- Curses.addstr(str.join)
- @screen.refresh
- c = Curses.getch
- case c
- when 27 # ESCAPE
- throw :done
- when Curses::KEY_ENTER, 13
- throw :done, @matches[@selected]
- when Curses::KEY_RIGHT, 9 # TAB
- item_incr(10)
- when Curses::KEY_LEFT, 353 # SHIT-TAB
- item_incr(-10)
- when Curses::KEY_UP, Curses::KEY_CTRL_P
- item_incr(-1)
- when Curses::KEY_DOWN, Curses::KEY_CTRL_N
- item_incr(1)
- when Curses::KEY_NPAGE
- item_incr(page_size)
- when Curses::KEY_PPAGE
- item_incr(-page_size)
- when Curses::KEY_BACKSPACE
- str.pop
- filter
- when (0..255)
- str << c.chr
- filter
- end
- end
- end
- end
-
- def shown_to
- shown_from + page_size
- end
-
- def page_size
- @screen.maxy - 2
- end
-
- def row(index = @selected)
- index - shown_from + 1
- end
-
- def select(index)
- render_item
- if index > shown_to
- render(index - shown_to + shown_from)
- elsif index < shown_from
- render(index)
- end
- @selected = index
- render_item index, true
- end
-
- def item_incr(incr)
- index = @selected + incr
- index = 0 if index < 0
- index = @matches.size - 1 unless index < @matches.size
- select index
- end
-
- def render_item(index = @selected, standout = false)
- Curses.setpos(row(index) , 0)
- @screen.clrtoeol
- Curses.standout if standout
- Curses.addstr @matches[index]
- Curses.standend if standout
- end
-
- def render(from = 0)
- @shown_from = from
- (0..page_size).map { |y| render_item y + from }
- end
+if __FILE__ == $0
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
+ require 'rubygems'
+end
- def filter
- pattern = str.join
- @selected = 0
- @matches = @finder.sorted_matches_for pattern
- render @selected
- render_item @selected, true
- end
+gem 'command-t'
-end
+require 'mrT'
-if $0 == __FILE__
- dir = Dir.pwd
- dir = ARGV.first if ARGV.first && File.directory?(ARGV.first)
- res = BashT.new(dir).run
- puts res if res
-end
+dir = Dir.pwd
+dir = ARGV.first if ARGV.first && File.directory?(ARGV.first)
+res = MrT.new(dir).run
+puts res if res
130 lib/mrT.rb
View
@@ -0,0 +1,130 @@
+require 'curses'
+require 'command-t/finder'
+
+class MrT
+
+ attr_reader :str, :shown_from, :pwd
+
+ def initialize(pwd)
+ @str = []
+ @options = {
+ }
+ @pwd = pwd
+ @finder = CommandT::Finder.new @pwd, @options
+ end
+
+ def run
+ value = with_curses { interact }
+ File.expand_path(value, @pwd) if value
+ end
+
+ def with_curses
+ Curses.init_screen
+ Curses.nonl
+ Curses.cbreak
+ Curses.noecho
+
+ @screen = Curses.stdscr
+ @screen.scrollok true
+ @screen.keypad true
+
+ begin
+ value = yield
+ rescue Interrupt
+ Curses.close_screen
+ ensure
+ Curses.close_screen
+ end
+ end
+
+ def interact
+ catch :done do
+ filter
+ while true
+ Curses.setpos(0,0)
+ @screen.clrtoeol
+ Curses.addstr('>> ')
+ Curses.addstr(str.join)
+ @screen.refresh
+ c = Curses.getch
+ case c
+ when 27 # ESCAPE
+ throw :done
+ when Curses::KEY_ENTER, 13
+ throw :done, @matches[@selected]
+ when Curses::KEY_RIGHT, 9 # TAB
+ item_incr(10)
+ when Curses::KEY_LEFT, 353 # SHIT-TAB
+ item_incr(-10)
+ when Curses::KEY_UP, Curses::KEY_CTRL_P
+ item_incr(-1)
+ when Curses::KEY_DOWN, Curses::KEY_CTRL_N
+ item_incr(1)
+ when Curses::KEY_NPAGE
+ item_incr(page_size)
+ when Curses::KEY_PPAGE
+ item_incr(-page_size)
+ when Curses::KEY_BACKSPACE
+ str.pop
+ filter
+ when (0..255)
+ str << c.chr
+ filter
+ end
+ end
+ end
+ end
+
+ def shown_to
+ shown_from + page_size
+ end
+
+ def page_size
+ @screen.maxy - 2
+ end
+
+ def row(index = @selected)
+ index - shown_from + 1
+ end
+
+ def select(index)
+ render_item
+ if index > shown_to
+ render(index - shown_to + shown_from)
+ elsif index < shown_from
+ render(index)
+ end
+ @selected = index
+ render_item index, true
+ end
+
+ def item_incr(incr)
+ index = @selected + incr
+ index = 0 if index < 0
+ index = @matches.size - 1 unless index < @matches.size
+ select index
+ end
+
+ def render_item(index = @selected, standout = false)
+ Curses.setpos(row(index) , 0)
+ @screen.clrtoeol
+ Curses.standout if standout
+ Curses.addstr @matches[index]
+ Curses.standend if standout
+ end
+
+ def render(from = 0)
+ @shown_from = from
+ (0..page_size).map { |y| render_item y + from }
+ end
+
+ def filter
+ pattern = str.join
+ @selected = 0
+ @matches = @finder.sorted_matches_for pattern
+ render @selected
+ render_item @selected, true
+ end
+
+end
+
35 mrT.gemspec
View
@@ -0,0 +1,35 @@
+Gem::Specification.new do |s|
+ s.name = "mrT"
+ v = `git describe --abbrev=0`.chomp
+ s.version = v
+
+ s.authors = ["Victor Hugo Borja"]
+ s.date = "2011-03-17"
+ s.email = "vic.borja@gmail.com"
+
+ files =
+ ["README.md", "LICENSE", "Gemfile", "Rakefile"] +
+ Dir.glob("{lib,bin}/**/*")
+
+ files = files.reject { |f| f =~ /\.(rbc|o|log|plist|dSYM)/ }
+
+ s.files = files
+ s.require_path = "lib"
+
+ s.executables = ["mrT"]
+
+ s.has_rdoc = false
+ s.homepage = "http://github.com/vic/mrT"
+
+ s.summary = "A curses based file finder using Command-T algorithm."
+
+ s.description = <<EOS
+ MrT is a tiny curses application that allows you to easily find a file
+ from your shell prompt. It uses the ruby binding from Command-T vim plugin[0].
+
+ You can use MrT standalone or as your default file completion function in bash.
+
+ [0] https://wincent.com/products/command-t
+EOS
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.