easyeditor 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "http://ruby.taobao.org"
2
+
3
+ # Specify your gem's dependencies in easyeditor.gemspec
4
+ gemspec
5
+ gem 'rspec'
6
+ gem 'guard'
7
+ gem 'guard-rspec'
8
+ gem 'libnotify'
9
+ gem 'awesome_print'
data/Guardfile ADDED
@@ -0,0 +1,19 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', :version => 2 do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+
9
+ # Rails example
10
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
13
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14
+ watch('config/routes.rb') { "spec/routing" }
15
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
16
+ # Capybara request specs
17
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
18
+ end
19
+
data/README ADDED
@@ -0,0 +1,11 @@
1
+ A tool for open file in a lazy way.
2
+
3
+ Install:
4
+ gem install easyeditor
5
+
6
+ Useage:
7
+ ee [-f vim(default)|emacs..] path/file
8
+
9
+ eg.
10
+ ee li/easyedit
11
+ That will open lib/easyeditor.rb
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/easyeditor ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- encoding : utf-8 -*-
3
+ def require_r(path) require(File.expand_path(path.to_s, File.dirname(__FILE__))) end
4
+
5
+ require_r "../lib/easyeditor"
6
+ require "optparse"
7
+
8
+ include Easyeditor
9
+ options = {}
10
+ option_parser = OptionParser.new do |opts|
11
+ opts.banner = 'Usage: ee -e [vim|vi..] path/file '
12
+ opts.on('-e vim|emacs', '--editor', 'Set editor') do |editor|
13
+ options[:editor] = editor
14
+ end
15
+ end.parse!
16
+ puts "Now open #{options[:editor]} #{ARGV.first}"
17
+ ee = EasyEditor.new(ARGV.first,(options[:editor] || "vim")).open
18
+
data/bin/ee ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- encoding : utf-8 -*-
3
+ def require_r(path) require(File.expand_path(path.to_s, File.dirname(__FILE__))) end
4
+
5
+ require_r "../lib/easyeditor"
6
+ require "optparse"
7
+
8
+ include Easyeditor
9
+ options = {}
10
+ option_parser = OptionParser.new do |opts|
11
+ opts.banner = 'Usage: ee -e [vim|vi..] path/file '
12
+ opts.on('-e vim|emacs', '--editor', 'Set editor') do |editor|
13
+ options[:editor] = editor
14
+ end
15
+ end.parse!
16
+ puts "Now open #{options[:editor]} #{ARGV.first}"
17
+ ee = EasyEditor.new(ARGV.first,(options[:editor] || "vim")).open
18
+
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "easyeditor/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "easyeditor"
7
+ s.version = Easyeditor::VERSION
8
+ s.authors = ["azhao"]
9
+ s.email = ["azhao.1981@gmail.com"]
10
+ s.homepage = "https://github.com/azhao1981/easyeditor"
11
+ s.summary = %q{Tool for easy to open Project file.}
12
+ s.description = %q{ee path1/path2/filename will open which one that match *path1*/*path2*/*file.* }
13
+
14
+ s.rubyforge_project = "easyeditor"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
24
+ end
@@ -0,0 +1,4 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module Easyeditor
3
+ VERSION = "0.0.2"
4
+ end
data/lib/easyeditor.rb ADDED
@@ -0,0 +1,51 @@
1
+ # -*- encoding : utf-8 -*-
2
+ def require_r(path) require(File.expand_path(path.to_s, File.dirname(__FILE__))) end
3
+
4
+ require_r "easyeditor/version"
5
+ require 'pathname'
6
+ require "ap"
7
+
8
+ module Easyeditor
9
+ class EasyEditor
10
+ attr_accessor :target_files
11
+ def initialize(path,editor="vim")
12
+ @editor = editor
13
+ @target_files = []
14
+ parse_path(path)
15
+ match_paths
16
+ return self
17
+ end
18
+ def open
19
+ if @target_files.length > 1
20
+ ap @target_files
21
+ puts "Which file to open:[0-default]"
22
+ @index = $stdin.gets.to_i
23
+ end
24
+ exec "#{@editor} #{@target_files[@index || 0]}"
25
+ end
26
+ def parse_path(path)
27
+ path_a = path.split('/')
28
+ @filename_str = path_a.delete_at(-1)
29
+ @path_str = path_a.join(".*/.*")
30
+ end
31
+ def match_paths
32
+ traverse_dir('.') do |file|
33
+ @target_files << file if is_match?(file)
34
+ end
35
+ end
36
+ def is_match?(path)
37
+ /#{@path_str}/.match(path) && /#{@filename_str}.*/.match(File.basename(path))
38
+ end
39
+ def traverse_dir(dir_path)
40
+ if File.directory? dir_path
41
+ Dir.foreach(dir_path) do |file|
42
+ if file!="." and file!=".."
43
+ traverse_dir(dir_path+"/"+file){|x| yield x}
44
+ end
45
+ end
46
+ else
47
+ yield dir_path
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,16 @@
1
+ # -*- encoding : utf-8 -*-
2
+ # Unit test for EasyEditor
3
+ #
4
+ #
5
+ require_relative "../lib/easyeditor"
6
+
7
+ include Easyeditor
8
+
9
+ describe EasyEditor do
10
+ before(:each) do
11
+ @ee = EasyEditor.new("lib/easyedito")
12
+ end
13
+ it "lib/easyeditor will get file :./lib/easyeditor.rb " do
14
+ @ee.target_files.should == ["./lib/easyeditor.rb"]
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: easyeditor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - azhao
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-11 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: ! 'ee path1/path2/filename will open which one that match *path1*/*path2*/*file.* '
15
+ email:
16
+ - azhao.1981@gmail.com
17
+ executables:
18
+ - easyeditor
19
+ - ee
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - .gitignore
24
+ - .rspec
25
+ - Gemfile
26
+ - Guardfile
27
+ - README
28
+ - Rakefile
29
+ - bin/easyeditor
30
+ - bin/ee
31
+ - easyeditor.gemspec
32
+ - lib/easyeditor.rb
33
+ - lib/easyeditor/version.rb
34
+ - spec/easyeditor_spec.rb
35
+ homepage: https://github.com/azhao1981/easyeditor
36
+ licenses: []
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubyforge_project: easyeditor
55
+ rubygems_version: 1.8.15
56
+ signing_key:
57
+ specification_version: 3
58
+ summary: Tool for easy to open Project file.
59
+ test_files: []