easyeditor 0.0.3 → 0.0.4

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 CHANGED
@@ -8,4 +8,10 @@ Useage:
8
8
 
9
9
  eg.
10
10
  ee li/easyedit
11
- That will open lib/easyeditor.rb
11
+ That will open lib/easyeditor.rb
12
+
13
+ BUG:
14
+ TODO: sudo support ...Look don't work
15
+ TODO: windows....I ready don't want to do this.....
16
+ DONE: don't work on ruby -v<1.9.3
17
+ DONE: directory support, no directory show.
data/bin/easyeditor CHANGED
@@ -3,6 +3,7 @@
3
3
  def require_r(path) require(File.expand_path(path.to_s, File.dirname(__FILE__))) end
4
4
 
5
5
  require_r "../lib/easyeditor"
6
+ require_r "../lib/easyeditor/version"
6
7
  require "optparse"
7
8
 
8
9
  include Easyeditor
@@ -13,6 +14,10 @@ option_parser = OptionParser.new do |opts|
13
14
  opts.on('-e vim|emacs', '--editor', 'Set editor') do |editor|
14
15
  options[:editor] = editor
15
16
  end
17
+ opts.on('-v','--version','Show version') do
18
+ puts "ee|easyeditor -v= #{VERSION} "
19
+ exit
20
+ end
16
21
  end.parse!
17
22
  puts "Now open #{options[:editor]} #{ARGV.first}"
18
23
  ee = EasyEditor.new(ARGV.first,options[:editor]).open
data/bin/ee CHANGED
@@ -3,6 +3,7 @@
3
3
  def require_r(path) require(File.expand_path(path.to_s, File.dirname(__FILE__))) end
4
4
 
5
5
  require_r "../lib/easyeditor"
6
+ require_r "../lib/easyeditor/version"
6
7
  require "optparse"
7
8
 
8
9
  include Easyeditor
@@ -13,7 +14,19 @@ option_parser = OptionParser.new do |opts|
13
14
  opts.on('-e vim|emacs', '--editor', 'Set editor') do |editor|
14
15
  options[:editor] = editor
15
16
  end
17
+ opts.on('-v','--version','Show version') do
18
+ puts "ee|easyeditor -v= #{VERSION} "
19
+ exit
20
+ end
21
+ options[:directory] = "."
22
+ opts.on('-d directory', '--directory', 'Set directory') do |directory|
23
+ options[:directory] = directory
24
+ end
25
+ options[:sudo] = false
26
+ opts.on('-s','--sudo',"Open with super user.") do
27
+ options[:sudo] = true
28
+ end
16
29
  end.parse!
17
30
  puts "Now open #{options[:editor]} #{ARGV.first}"
18
- ee = EasyEditor.new(ARGV.first,options[:editor]).open
31
+ ee = EasyEditor.new(ARGV.first,options).open
19
32
 
data/easyeditor.gemspec CHANGED
@@ -21,4 +21,5 @@ Gem::Specification.new do |s|
21
21
  # specify any dependencies here; for example:
22
22
  # s.add_development_dependency "rspec"
23
23
  # s.add_runtime_dependency "rest-client"
24
+ s.add_runtime_dependency "awesome_print"
24
25
  end
@@ -1,4 +1,4 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module Easyeditor
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
data/lib/easyeditor.rb CHANGED
@@ -8,9 +8,11 @@ require "ap"
8
8
  module Easyeditor
9
9
  class EasyEditor
10
10
  attr_accessor :target_files
11
- def initialize(path,editor="vim")
12
- @editor = editor
11
+ def initialize(path,options={})
12
+ @editor = options[:editor]
13
13
  @target_files = []
14
+ @dir = options[:directory]
15
+ @sudo_flag = options[:sudo]
14
16
  parse_path(path)
15
17
  match_paths
16
18
  return self
@@ -21,7 +23,10 @@ module Easyeditor
21
23
  puts "Which file to open:[0-default]"
22
24
  @index = $stdin.gets.to_i
23
25
  end
24
- exec "#{@editor} #{@target_files[@index || 0]}"
26
+ exec "#{sudo}#{@editor} #{@target_files[@index || 0]}"
27
+ end
28
+ def sudo
29
+ "sudo " if @sudo_flag
25
30
  end
26
31
  def parse_path(path)
27
32
  path_a = path.split('/')
@@ -29,13 +34,14 @@ module Easyeditor
29
34
  @path_str = path_a.join(".*/.*")
30
35
  end
31
36
  def match_paths
32
- traverse_dir('.') do |file|
37
+ traverse_dir(@dir) do |file|
33
38
  @target_files << file if is_match?(file)
34
39
  end
35
40
  end
36
41
  def is_match?(path)
37
- /#{@path_str}/.match(path) && /#{@filename_str}.*/.match(File.basename(path))
42
+ !File.directory?(path) && /#{@path_str}/.match(path) && /#{@filename_str}.*/.match(File.basename(path))
38
43
  end
44
+ # 遍历文件夹
39
45
  def traverse_dir(dir_path)
40
46
  if File.directory? dir_path
41
47
  Dir.foreach(dir_path) do |file|
@@ -8,7 +8,8 @@ include Easyeditor
8
8
 
9
9
  describe EasyEditor do
10
10
  before(:each) do
11
- @ee = EasyEditor.new("lib/easyedito")
11
+ options = {:editor=>"vim",:directory=>".",:sudo_flag=>false}
12
+ @ee = EasyEditor.new("lib/easyedito",options)
12
13
  end
13
14
  it "lib/easyeditor will get file :./lib/easyeditor.rb " do
14
15
  @ee.target_files.should == ["./lib/easyeditor.rb"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easyeditor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,19 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-12 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2012-02-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: awesome_print
16
+ requirement: &82692220 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *82692220
14
25
  description: ! 'ee path1/path2/filename will open which one that match *path1*/*path2*/*file.* '
15
26
  email:
16
27
  - azhao.1981@gmail.com