Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for an overrides file. #4

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions ruby/command-t/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@
require 'command-t/finder'
require 'command-t/match_window'
require 'command-t/prompt'
require 'yaml'

module CommandT
class Controller
def initialize
@prompt = Prompt.new
@override_definitions_file = ".command-t.yaml"
set_up_max_height
set_up_finder
end
Expand All @@ -45,6 +47,7 @@ def show
@focus = @prompt
@prompt.focus
register_for_key_presses
read_overrides
clear # clears prompt and lists matches
rescue Errno::ENOENT
# probably a problem with the optional parameter
Expand Down Expand Up @@ -237,6 +240,24 @@ def vt100?
!!(::VIM::evaluate('&term') =~ /\Avt100/)
end

def read_overrides
begin
if File.file?(@override_definitions_file)
file_contents = IO.read(@override_definitions_file)
ruby_obj = YAML::load(file_contents)
if ruby_obj.has_key?("overrides")
@overrides = ruby_obj["overrides"]
else
raise "Key does not exist"
end
else
raise "IO Error"
end
rescue
@overrides = Hash.new()
end
end

def register_for_key_presses
# "normal" keys (interpreted literally)
numbers = ('0'..'9').to_a.join
Expand Down Expand Up @@ -286,6 +307,11 @@ def match_limit

def list_matches
matches = @finder.sorted_matches_for @prompt.abbrev, :limit => match_limit
@overrides.each_pair do |k,v|
if @prompt.abbrev == k
matches.insert(0, v)
end
end
@match_window.matches = matches
end
end # class Controller
Expand Down