diff options
| author | Miquel Sabaté Solà <msabate@suse.com> | 2019-08-22 18:30:24 +0200 |
|---|---|---|
| committer | Miquel Sabaté Solà <msabate@suse.com> | 2019-08-22 18:30:24 +0200 |
| commit | 4ead9be4468d8d58c027bf6e6616e3b4d6e727eb (patch) | |
| tree | 18ab19fd5213c9d302b165eafa46a6f1f8902e75 /rake_completion | |
| parent | 04f4a7df197ce327f36b666869a1ca2f09934e58 (diff) | |
| download | dotfiles-4ead9be4468d8d58c027bf6e6616e3b4d6e727eb.tar.gz dotfiles-4ead9be4468d8d58c027bf6e6616e3b4d6e727eb.zip | |
Complete re-structuring so it's easier to install
Signed-off-by: Miquel Sabaté Solà <msabate@suse.com>
Diffstat (limited to 'rake_completion')
| -rwxr-xr-x | rake_completion | 69 |
1 files changed, 0 insertions, 69 deletions
diff --git a/rake_completion b/rake_completion deleted file mode 100755 index a142dc7..0000000 --- a/rake_completion +++ /dev/null @@ -1,69 +0,0 @@ -#!/usr/bin/env ruby - -# to install, add the following line to your .bash_profile or .bashrc -# complete -C path/to/rake_completion -o default rake - -# Rake completion will return matching rake tasks given typed text. This way -# you can auto-complete tasks as you are typing them by hitting [tab] or [tab][tab] -# This also caches the rake tasks for optimium speed -class RakeCompletion - CACHE_FILE_NAME = '.rake_tasks' - - def initialize(command) - @command = command - end - - def matches - exit 0 if rakefile.nil? - matching_tasks.map do |task| - task.sub(typed_before_colon, '') - end - end - - private - - def typed - @command[/\s(.+?)$/, 1] || '' - end - - def typed_before_colon - typed[/.+\:/] || '' - end - - def matching_tasks - all_tasks.select do |task| - task[0, typed.length] == typed - end - end - - def all_tasks - cache_current? ? tasks_from_cache : generate_tasks - end - - def cache_current? - File.exist?(cache_file) && File.mtime(cache_file) >= File.mtime(rakefile) - end - - def rakefile - ['rakefile', 'Rakefile', 'rakefile.rb', 'Rakefile.rb'].detect do |file| - File.file? File.join(Dir.pwd, file) - end - end - - def cache_file - File.join(Dir.pwd, CACHE_FILE_NAME) - end - - def tasks_from_cache - IO.read(cache_file).split - end - - def generate_tasks - tasks = `rake --tasks`.split("\n")[1..-1].collect {|line| line.split[1]} - File.open(cache_file, 'w') { |f| f.write tasks.join("\n") } - tasks - end -end - -puts RakeCompletion.new(ENV["COMP_LINE"]).matches -exit 0 |
