act 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/act.gemspec +27 -0
- data/bin/act +12 -0
- data/lib/act.rb +6 -0
- data/lib/act/command.rb +74 -0
- data/lib/act/helper.rb +76 -0
- data/lib/act/version.rb +3 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3936088dcf64820eb627fd2a7e4fbe3640dc9782
|
4
|
+
data.tar.gz: bc4c3220f8e74657df4246d715e63027f3a62313
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 045fdafee182130af6c785b992b08677b317c66cf03fa9cd561ed8c76e2d7a907d080e0e3dcf5ccac729d7b26c7261832d8a14023d3e557ce711831d9acc5595
|
7
|
+
data.tar.gz: 237036db380d5e761742c5be30b41daa8a598d6581d47f26370326b072604bcf345f97a77fc21981c22639bd0de2707b8a716166e3cf9690e944e749dc4c05cc
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Fabio Pelosin
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Act
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'act'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install act
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://github.com/[my-github-username]/act/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/act.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'act/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "act"
|
8
|
+
spec.version = Act::VERSION
|
9
|
+
spec.authors = ["Fabio Pelosin"]
|
10
|
+
spec.email = ["fabiopelosin@gmail.com"]
|
11
|
+
spec.summary = %q{Act the command line tool to act on files}
|
12
|
+
# spec.description = %q{TODO: Write a longer description. Optional.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "claide", "~> 0.5"
|
22
|
+
spec.add_runtime_dependency "colored", "~> 1.2"
|
23
|
+
spec.add_runtime_dependency "activesupport"
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
26
|
+
spec.add_development_dependency "rake"
|
27
|
+
end
|
data/bin/act
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
if $PROGRAM_NAME == __FILE__ && !ENV['COCOAPODS_NO_BUNDLER']
|
4
|
+
ENV['BUNDLE_GEMFILE'] = File.expand_path('../../Gemfile', __FILE__)
|
5
|
+
require "rubygems"
|
6
|
+
require "bundler/setup"
|
7
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
require 'act'
|
12
|
+
Act::Command.run(ARGV)
|
data/lib/act.rb
ADDED
data/lib/act/command.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'colored'
|
2
|
+
require 'claide'
|
3
|
+
require 'active_support/core_ext/string/strip'
|
4
|
+
|
5
|
+
module Act
|
6
|
+
class Command < CLAide::Command
|
7
|
+
|
8
|
+
self.command = 'act'
|
9
|
+
self.description = 'Act the command line tool to act on files'
|
10
|
+
|
11
|
+
def self.options
|
12
|
+
[
|
13
|
+
['--open', "Open the file in $EDITOR instead of printing it"],
|
14
|
+
['--no-line-numbers', "Show output without line numbers"],
|
15
|
+
['--version', 'Show the version of Act'],
|
16
|
+
].concat(super)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.run(argv)
|
20
|
+
argv = CLAide::ARGV.new(argv)
|
21
|
+
if argv.flag?('version')
|
22
|
+
puts VERSION
|
23
|
+
exit 0
|
24
|
+
end
|
25
|
+
super(argv)
|
26
|
+
end
|
27
|
+
|
28
|
+
def initialize(argv)
|
29
|
+
@open = argv.flag?('open')
|
30
|
+
@number_lines = argv.flag?('line-numbers', true)
|
31
|
+
@file = argv.shift_argument
|
32
|
+
super
|
33
|
+
end
|
34
|
+
|
35
|
+
def validate!
|
36
|
+
super
|
37
|
+
help! "A file is required." unless @file
|
38
|
+
end
|
39
|
+
|
40
|
+
def run
|
41
|
+
file_information = @file.split(':')
|
42
|
+
path = file_information[0]
|
43
|
+
line = file_information[1]
|
44
|
+
context_lines = 5
|
45
|
+
|
46
|
+
if @open
|
47
|
+
command = Helper.open_in_editor_command(path, line)
|
48
|
+
system(command)
|
49
|
+
else
|
50
|
+
string = File.read(path) if File.exists?(path)
|
51
|
+
|
52
|
+
if string
|
53
|
+
if line
|
54
|
+
line = line.to_i
|
55
|
+
start_line = Helper.start_line(string, line, context_lines)
|
56
|
+
end_line = Helper.end_line(string, line, context_lines)
|
57
|
+
string = Helper.select_lines(string, start_line, end_line)
|
58
|
+
puts "Showing from line #{start_line} to #{end_line}"
|
59
|
+
end
|
60
|
+
|
61
|
+
string = Helper.strip_indentation(string)
|
62
|
+
string = Helper.syntax_highlith(string, path) if self.ansi_output?
|
63
|
+
string = Helper.add_line_numbers(string, start_line, line) if @number_lines
|
64
|
+
|
65
|
+
puts
|
66
|
+
puts string
|
67
|
+
else
|
68
|
+
puts "[!] File not found"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
data/lib/act/helper.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'colored'
|
2
|
+
require 'active_support/core_ext/string/strip'
|
3
|
+
require 'open3'
|
4
|
+
|
5
|
+
module Act
|
6
|
+
module Helper
|
7
|
+
|
8
|
+
# @return [String]
|
9
|
+
#
|
10
|
+
def self.open_in_editor_command(path, line)
|
11
|
+
editor = ENV['EDITOR']
|
12
|
+
result = "#{editor} #{path}"
|
13
|
+
if line
|
14
|
+
case editor
|
15
|
+
when 'vim', 'mvim'
|
16
|
+
result = "#{editor} #{path} +#{line}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
result
|
20
|
+
end
|
21
|
+
|
22
|
+
# @return [Fixnum]
|
23
|
+
#
|
24
|
+
def self.start_line(string, line, context_lines)
|
25
|
+
start_line = line - context_lines - 1
|
26
|
+
end
|
27
|
+
|
28
|
+
# @return [Fixnum]
|
29
|
+
#
|
30
|
+
def self.end_line(string, line, context_lines)
|
31
|
+
end_line = line + context_lines - 1
|
32
|
+
end
|
33
|
+
|
34
|
+
# @return [String]
|
35
|
+
#
|
36
|
+
def self.select_lines(string, start_line, end_line)
|
37
|
+
string.lines[start_line..end_line].join
|
38
|
+
end
|
39
|
+
|
40
|
+
# @return [String]
|
41
|
+
#
|
42
|
+
def self.strip_indentation(string)
|
43
|
+
string.strip_heredoc
|
44
|
+
end
|
45
|
+
|
46
|
+
# @return [String]
|
47
|
+
#
|
48
|
+
def self.add_line_numbers(string, start_line, highlight_line = nil)
|
49
|
+
line_count = start_line
|
50
|
+
numbered_lines = string.lines.map do |line|
|
51
|
+
line_count += 1
|
52
|
+
number = line_count.to_s.ljust(3)
|
53
|
+
if highlight_line && highlight_line == line_count
|
54
|
+
number = number.yellow
|
55
|
+
end
|
56
|
+
"#{number} #{line}"
|
57
|
+
end
|
58
|
+
numbered_lines.join
|
59
|
+
end
|
60
|
+
|
61
|
+
# @return [String]
|
62
|
+
#
|
63
|
+
def self.syntax_highlith(string, file_name)
|
64
|
+
return string if `which gen_bridge_metadata`.strip.empty?
|
65
|
+
result = nil
|
66
|
+
lexer = `pygmentize -N #{file_name}`.chomp
|
67
|
+
Open3.popen3("pygmentize -l #{lexer}") do |stdin, stdout, stderr|
|
68
|
+
stdin.write(string)
|
69
|
+
stdin.close_write
|
70
|
+
result = stdout.read
|
71
|
+
end
|
72
|
+
result
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
data/lib/act/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: act
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Fabio Pelosin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: claide
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.5'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: colored
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activesupport
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.6'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.6'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- fabiopelosin@gmail.com
|
86
|
+
executables:
|
87
|
+
- act
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- act.gemspec
|
97
|
+
- bin/act
|
98
|
+
- lib/act.rb
|
99
|
+
- lib/act/command.rb
|
100
|
+
- lib/act/helper.rb
|
101
|
+
- lib/act/version.rb
|
102
|
+
homepage: ''
|
103
|
+
licenses:
|
104
|
+
- MIT
|
105
|
+
metadata: {}
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 2.2.2
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: Act the command line tool to act on files
|
126
|
+
test_files: []
|
127
|
+
has_rdoc:
|