act 0.0.2 → 0.0.3
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.
- checksums.yaml +4 -4
- data/Gemfile +3 -3
- data/README.md +2 -2
- data/lib/act/command.rb +58 -23
- data/lib/act/helper.rb +33 -4
- data/lib/act/version.rb +1 -1
- data/spec/helper_spec.rb +16 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2faf8a1d513d94638d664661519f8b40df95c6ca
|
4
|
+
data.tar.gz: 7e4c4df4a3971d1b64c138793df53526adfcbb4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d9ab8baa30dd2bc07755fab8a4a456c866a2b32b1cf4ed9a8f233500475348c44af6c9919cf40f30d381d4b644969b16982ad472296a68b1a1e401191ef7271
|
7
|
+
data.tar.gz: 2cb5dbe4bd494e7a037e294e90e7e79ae7435d830d71bfa4b90ad6b6f320f93e5fe72b7d1ee2ae650f21b6b5706275e6ebe4bf29a4a262bb84d3f082480f48eb
|
data/Gemfile
CHANGED
@@ -3,13 +3,13 @@ source 'https://rubygems.org'
|
|
3
3
|
gemspec
|
4
4
|
|
5
5
|
group :development do
|
6
|
-
gem
|
7
|
-
gem
|
6
|
+
gem 'bacon'
|
7
|
+
gem 'mocha-on-bacon'
|
8
8
|
gem 'prettybacon'
|
9
9
|
gem 'rubocop'
|
10
10
|
end
|
11
11
|
|
12
12
|
group :debugging do
|
13
|
-
gem
|
13
|
+
gem 'kicker'
|
14
14
|
end
|
15
15
|
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Act
|
2
2
|
[](https://travis-ci.org/irrationalfab/act)
|
3
3
|
|
4
|
-
|
4
|
+
Preview files from the command line efficiently. `cat` for the twenty first century!
|
5
5
|
|
6
6
|
<img src="http://cl.ly/image/0A2p320r442D/Image%202014-04-04%20at%202.59.18%20pm.png" height="50%" width="50%">
|
7
7
|
|
@@ -11,7 +11,7 @@ Allows to act on files from the command line efficiently... `cat` for the twenty
|
|
11
11
|
- Support for colon syntax
|
12
12
|
- Support for GitHub like URLs
|
13
13
|
- Automatic syntax highlighting based on the file extension (via [Pygments](http://pygments.org))
|
14
|
-
- Fast
|
14
|
+
- Fast enough for the task
|
15
15
|
|
16
16
|
## Installation
|
17
17
|
|
data/lib/act/command.rb
CHANGED
@@ -5,58 +5,81 @@ require 'active_support/core_ext/string/strip'
|
|
5
5
|
module Act
|
6
6
|
class Command < CLAide::Command
|
7
7
|
self.command = 'act'
|
8
|
-
|
8
|
+
|
9
|
+
self.description = <<-DOC
|
10
|
+
Act the command line tool to act on files
|
11
|
+
|
12
|
+
Prints the contents of the file at `PATH`.
|
13
|
+
|
14
|
+
DOC
|
15
|
+
|
16
|
+
def self.arguments
|
17
|
+
[
|
18
|
+
['PATH', :optional],
|
19
|
+
]
|
20
|
+
end
|
9
21
|
|
10
22
|
def self.options
|
11
23
|
[
|
12
24
|
['--open', 'Open the file in $EDITOR instead of printing it'],
|
13
|
-
['--
|
14
|
-
['--
|
25
|
+
['--prettify', "Don't prettify output"],
|
26
|
+
['--line-numbers', 'Show output without line numbers'],
|
27
|
+
['--lexer=NAME', 'Use the given lexer'],
|
15
28
|
].concat(super)
|
16
29
|
end
|
17
30
|
|
18
|
-
def self.
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
24
|
-
super(argv)
|
31
|
+
def self.completion_description
|
32
|
+
description = super
|
33
|
+
# _path_files function
|
34
|
+
description[:paths] = :all_files
|
35
|
+
description
|
25
36
|
end
|
26
37
|
|
27
38
|
def initialize(argv)
|
39
|
+
@stdin = STDIN.read unless STDIN.tty?
|
28
40
|
@open = argv.flag?('open')
|
29
|
-
@
|
41
|
+
@prettify = argv.flag?('prettify', false)
|
42
|
+
@number_lines = argv.flag?('line-numbers', false)
|
43
|
+
@lexer = argv.option('lexer', false)
|
30
44
|
@file_string = argv.shift_argument
|
31
45
|
super
|
32
46
|
end
|
33
47
|
|
34
48
|
def validate!
|
35
49
|
super
|
36
|
-
help! 'A file is required.' unless @file_string
|
50
|
+
help! 'A file is required.' unless @file_string || @open || @stdin
|
37
51
|
end
|
38
52
|
|
39
53
|
CONTEXT_LINES = 5
|
40
54
|
|
41
55
|
def run
|
56
|
+
if @stdin && !@open
|
57
|
+
cat_string(@stdin)
|
58
|
+
return
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
@file_string ||= '.'
|
42
63
|
clean_file_string = pre_process_file_string(@file_string)
|
43
64
|
file = ArgumentParser.parse_file_information(clean_file_string, CONTEXT_LINES)
|
44
65
|
|
45
66
|
path_exists = File.exist?(file.path)
|
46
67
|
unless path_exists
|
47
68
|
inferred = infer_local_path(file.path)
|
48
|
-
|
49
|
-
|
69
|
+
if inferred
|
70
|
+
file.path = inferred
|
71
|
+
path_exists = true
|
72
|
+
end
|
50
73
|
end
|
51
74
|
|
52
|
-
if
|
53
|
-
|
54
|
-
|
55
|
-
|
75
|
+
if @open
|
76
|
+
open_file(file)
|
77
|
+
else
|
78
|
+
if path_exists
|
56
79
|
cat_file(file)
|
80
|
+
else
|
81
|
+
UI.warn '[!] File not found'
|
57
82
|
end
|
58
|
-
else
|
59
|
-
UI.warn '[!] File not found'
|
60
83
|
end
|
61
84
|
end
|
62
85
|
|
@@ -85,7 +108,13 @@ module Act
|
|
85
108
|
line = file.highlight_line || file.from_line
|
86
109
|
command = Helper.open_in_editor_command(file.path, line)
|
87
110
|
UI.puts command if self.verbose?
|
88
|
-
|
111
|
+
if defined? Bundler
|
112
|
+
Bundler.with_clean_env do
|
113
|
+
system(command)
|
114
|
+
end
|
115
|
+
else
|
116
|
+
system(command)
|
117
|
+
end
|
89
118
|
end
|
90
119
|
|
91
120
|
# @return [void]
|
@@ -95,11 +124,17 @@ module Act
|
|
95
124
|
if file.from_line && file.to_line
|
96
125
|
string = Helper.select_lines(string, file.from_line, file.to_line)
|
97
126
|
end
|
127
|
+
cat_string(string, file)
|
128
|
+
end
|
98
129
|
|
130
|
+
def cat_string(string, file = nil)
|
99
131
|
if string
|
132
|
+
path = file.path if file
|
133
|
+
@lexer ||= Helper.lexer(path)
|
100
134
|
string = Helper.strip_indentation(string)
|
101
|
-
string = Helper.
|
102
|
-
string = Helper.
|
135
|
+
string = Helper.prettify(string, @lexer) if @prettify
|
136
|
+
string = Helper.syntax_highlith(string, @lexer) if self.ansi_output?
|
137
|
+
string = Helper.add_line_numbers(string, file.from_line, file.highlight_line) if @number_lines && file
|
103
138
|
UI.puts "\n#{string}"
|
104
139
|
else
|
105
140
|
UI.warn '[!] Nothing to show'
|
data/lib/act/helper.rb
CHANGED
@@ -50,7 +50,7 @@ module Act
|
|
50
50
|
# @return [String]
|
51
51
|
#
|
52
52
|
def self.add_line_numbers(string, start_line, highlight_line = nil)
|
53
|
-
start_line ||=
|
53
|
+
start_line ||= 1
|
54
54
|
line_count = start_line
|
55
55
|
numbered_lines = string.lines.map do |line|
|
56
56
|
number = line_count.to_s.ljust(3)
|
@@ -63,12 +63,40 @@ module Act
|
|
63
63
|
numbered_lines.join
|
64
64
|
end
|
65
65
|
|
66
|
+
def self.lexer(file_name)
|
67
|
+
case file_name
|
68
|
+
when 'Gemfile', 'Rakefile', 'Podfile'
|
69
|
+
'rb'
|
70
|
+
when 'Podfile.lock', 'Gemfile.lock'
|
71
|
+
'yaml'
|
72
|
+
else
|
73
|
+
if file_name
|
74
|
+
`pygmentize -N #{file_name}`.chomp
|
75
|
+
else
|
76
|
+
'text'
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.prettify(string, lexer)
|
82
|
+
raise ArgumentError unless string
|
83
|
+
raise ArgumentError unless lexer
|
84
|
+
case lexer
|
85
|
+
when 'json'
|
86
|
+
require 'json'
|
87
|
+
JSON.pretty_generate(JSON.parse(string))
|
88
|
+
else
|
89
|
+
string
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
66
93
|
# @return [String]
|
67
94
|
#
|
68
|
-
def self.syntax_highlith(string,
|
69
|
-
|
95
|
+
def self.syntax_highlith(string, lexer)
|
96
|
+
raise ArgumentError unless string
|
97
|
+
raise ArgumentError unless lexer
|
98
|
+
return string if `which pygmentize`.strip.empty?
|
70
99
|
result = nil
|
71
|
-
lexer = `pygmentize -N #{file_name}`.chomp
|
72
100
|
Open3.popen3("pygmentize -l #{lexer}") do |stdin, stdout, stderr|
|
73
101
|
stdin.write(string)
|
74
102
|
stdin.close_write
|
@@ -76,5 +104,6 @@ module Act
|
|
76
104
|
end
|
77
105
|
result
|
78
106
|
end
|
107
|
+
|
79
108
|
end
|
80
109
|
end
|
data/lib/act/version.rb
CHANGED
data/spec/helper_spec.rb
CHANGED
@@ -51,5 +51,21 @@ module Act
|
|
51
51
|
|
52
52
|
#-------------------------------------------------------------------------#
|
53
53
|
|
54
|
+
describe 'lexer' do
|
55
|
+
it 'infers the lexer according to the extension using pygmentize' do
|
56
|
+
file_name = 'test.rb'
|
57
|
+
result = @subject.lexer(file_name)
|
58
|
+
result.should == 'rb'
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'infers the lexer according to the file name' do
|
62
|
+
file_name = 'Gemfile'
|
63
|
+
result = @subject.lexer(file_name)
|
64
|
+
result.should == 'rb'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
#-------------------------------------------------------------------------#
|
69
|
+
|
54
70
|
end
|
55
71
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: act
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fabio Pelosin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: claide
|