rake-command-completion 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Readme +22 -0
- data/bin/command_completion_for_rake +59 -0
- data/lib/empty.rb +1 -0
- metadata +51 -0
data/Readme
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
= Rake Command Completion
|
2
|
+
|
3
|
+
[*Environment*:] Rake command-line tool
|
4
|
+
[<b>Public project site</b>:] forthcoming
|
5
|
+
|
6
|
+
== Introduction
|
7
|
+
|
8
|
+
When you type <tt>rake<tab><tab></tt> you will get a list of available tasks for the project directory you are currently in.
|
9
|
+
|
10
|
+
The first time you do that, it has to rebuild its cache, which is kind of slow. After you do it once, however, a cached list of tasks (one list per project directory) is stored in <tt>~/.rake_task_cache/</tt>, speeding things up dramatically .
|
11
|
+
|
12
|
+
The cache will automatically be rebuilt every time you change your Rakefile (it will detect that the modified date of your Rakefile is newer than that of the cache file).
|
13
|
+
|
14
|
+
== Installation
|
15
|
+
|
16
|
+
Install the gem:
|
17
|
+
|
18
|
+
sudo gem install rake-command-completion
|
19
|
+
|
20
|
+
Add this line to your <tt>~/.bashrc</tt> file:
|
21
|
+
|
22
|
+
complete -C /usr/bin/command_completion_for_rake -o default rake
|
@@ -0,0 +1,59 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Complete rake tasks script for bash
|
4
|
+
#
|
5
|
+
# Save it somewhere and then add
|
6
|
+
# complete -C path/to/script -o default rake
|
7
|
+
# to your ~/.bashrc
|
8
|
+
#
|
9
|
+
# Authors:
|
10
|
+
# * Nicholas Seckar <nseckar@gmail.com>
|
11
|
+
# * Saimon Moore <saimon@webtypes.com> <http://www.webtypes.com/2006/03/31/rake-completion-script-that-handles-namespaces>
|
12
|
+
# * Err the Blog <http://errtheblog.com/post/33>
|
13
|
+
# * Lee Marlow <http://www.onrails.org/articles/2006/11/17/rake-command-completion-using-rake>
|
14
|
+
# * Tyler Rick <@qualitysmith.com>
|
15
|
+
|
16
|
+
exit 0 unless File.file?(File.join(Dir.pwd, 'Rakefile'))
|
17
|
+
|
18
|
+
require 'rubygems'
|
19
|
+
require 'rake'
|
20
|
+
|
21
|
+
class String
|
22
|
+
#irb -> "/path/to/..!-$terrible_file^#name.rb&".gsub(/\W/, '_')
|
23
|
+
# => "_path_to______terrible_file__name_rb_"
|
24
|
+
def to_safe_filename
|
25
|
+
self.gsub(/\W/, '_')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
#rake_task_cache_filename = File.join(File.expand_path('~'), ".rake_task_cache" , Dir.pwd.hash.to_s) # I didn't see the point in needlessly obfuscating this by making it a hash, so I changed the filename to be approximately the path of the project to which this list applies...
|
29
|
+
rake_task_cache_filename = File.join(File.expand_path('~'), ".rake_task_cache" , Dir.pwd.to_safe_filename.to_s)
|
30
|
+
|
31
|
+
# By making the rakefiles into dependencies for the cache file, it will cause the cache file to be regenerated when and only when one of the rakefiles is modified.
|
32
|
+
file rake_task_cache_filename => FileList[ 'Rakefile', 'lib/tasks/**/*.rake', 'vendor/plugins/*/tasks/**/*.rake'] do
|
33
|
+
tasks = `rake --silent --tasks`.split("\n")[1..-1].map { |line| line.split[1] }
|
34
|
+
require 'fileutils'
|
35
|
+
dirname = File.dirname(rake_task_cache_filename)
|
36
|
+
FileUtils.mkdir_p(dirname) unless File.exists?(dirname)
|
37
|
+
File.open(rake_task_cache_filename, 'w') { |f| f.puts tasks }
|
38
|
+
end
|
39
|
+
|
40
|
+
Rake::Task[rake_task_cache_filename].invoke # Actually generate the cache if it needs to be generated.
|
41
|
+
tasks = File.read(rake_task_cache_filename)
|
42
|
+
|
43
|
+
# COMP_LINE will be something like 'rake tes' (what they started to type)
|
44
|
+
# Not sure why this would ever *not* match but this line was here when I got to it... -Tyler
|
45
|
+
exit 0 unless /^rake\b/ =~ ENV["COMP_LINE"]
|
46
|
+
|
47
|
+
after_match = $'
|
48
|
+
task_match = (after_match.empty? || after_match =~ /\s$/) ? nil : after_match.split.last
|
49
|
+
tasks = tasks.select { |t| /^#{Regexp.escape task_match}/ =~ t } if task_match
|
50
|
+
|
51
|
+
# Handle namespaces
|
52
|
+
if task_match =~ /^([-\w:]+:)/
|
53
|
+
upto_last_colon = $1
|
54
|
+
after_match = $'
|
55
|
+
tasks = tasks.map { |t| (t =~ /^#{Regexp.escape upto_last_colon}([-\w:]+)$/) ? "#{$1}" : t }
|
56
|
+
end
|
57
|
+
|
58
|
+
puts tasks
|
59
|
+
exit 0
|
data/lib/empty.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Needed so that it doesn't complain "File not found: lib" during gem install
|
metadata
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.8.11
|
3
|
+
specification_version: 1
|
4
|
+
name: rake-command-completion
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.0.1
|
7
|
+
date: 2007-03-14 00:00:00 -07:00
|
8
|
+
summary: Adds bash command-line completion for the rake command.
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: rubyforge.org@tylerrick.com
|
12
|
+
homepage: http://rake-completion.rubyforge.org/
|
13
|
+
rubyforge_project: rake-command-completion
|
14
|
+
description: Adds bash command-line completion for the rake command.
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
authors:
|
29
|
+
- Nicholas Seckar, Saimon Moore, Err the Blog, Lee Marlow, Tyler Rick
|
30
|
+
files:
|
31
|
+
- lib/empty.rb
|
32
|
+
- bin/command_completion_for_rake
|
33
|
+
- Readme
|
34
|
+
test_files: []
|
35
|
+
|
36
|
+
rdoc_options:
|
37
|
+
- --title
|
38
|
+
- rake-command-completion
|
39
|
+
- --main
|
40
|
+
- Readme
|
41
|
+
- --line-numbers
|
42
|
+
extra_rdoc_files:
|
43
|
+
- Readme
|
44
|
+
executables:
|
45
|
+
- command_completion_for_rake
|
46
|
+
extensions: []
|
47
|
+
|
48
|
+
requirements: []
|
49
|
+
|
50
|
+
dependencies: []
|
51
|
+
|