bcat 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +13 -0
- data/bcat.gemspec +2 -1
- data/bin/bcat +22 -3
- data/lib/bcat.rb +18 -7
- data/man/bcat.1.ronn +13 -3
- metadata +4 -3
data/README
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
bcat reads from standard input and displays output in a web browser:
|
2
|
+
|
3
|
+
$ echo "hi mom" |bcat
|
4
|
+
$ echo "hi mom" |bcat -t 'Page Title'
|
5
|
+
$ echo "*hi mom*" |markdown |bcat -h
|
6
|
+
|
7
|
+
Browser output is displayed progressively as it's read from standard input,
|
8
|
+
making bcat especially useful with build tools and commands like tail(1) that
|
9
|
+
generate output over longer periods of time:
|
10
|
+
|
11
|
+
$ make all |bcat
|
12
|
+
$ rake test |bcat
|
13
|
+
$ tail -f /var/log/syslog |bcat
|
data/bcat.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'bcat'
|
3
|
-
s.version = '0.0.
|
3
|
+
s.version = '0.0.1'
|
4
4
|
s.date = '2010-06-19'
|
5
5
|
|
6
6
|
s.summary = "browser cat"
|
@@ -13,6 +13,7 @@ Gem::Specification.new do |s|
|
|
13
13
|
|
14
14
|
# = MANIFEST =
|
15
15
|
s.files = %w[
|
16
|
+
README
|
16
17
|
Rakefile
|
17
18
|
bcat.gemspec
|
18
19
|
bin/bcat
|
data/bin/bcat
CHANGED
@@ -1,8 +1,27 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
|
2
|
+
#/ Usage: bcat [-h] [<file>]...
|
3
|
+
#/ Read standard input, or one or more <file>s, and write to browser.
|
4
|
+
#/
|
5
|
+
#/ Options
|
6
|
+
#/ -h, --html input is html encoded
|
7
|
+
#/ -t, --title=<text> use <text> as the page title
|
8
|
+
require 'optparse'
|
4
9
|
require 'bcat'
|
5
10
|
|
11
|
+
options = {
|
12
|
+
:html => false,
|
13
|
+
:title => Dir.pwd,
|
14
|
+
:Host => 'localhost',
|
15
|
+
:Port => 8091
|
16
|
+
}
|
17
|
+
|
18
|
+
ARGV.options do |argv|
|
19
|
+
argv.on('-h', '--html') { options[:html] = true }
|
20
|
+
argv.on('-t', '--title=v') { |text| options[:title] = text }
|
21
|
+
argv.on_tail('--help') { exec "grep ^#/ <#{__FILE__} | cut -c4-" }
|
22
|
+
argv.parse!
|
23
|
+
end
|
24
|
+
|
6
25
|
fds =
|
7
26
|
ARGV.map do |file|
|
8
27
|
if file == '-'
|
@@ -17,7 +36,7 @@ command = ENV['BCAT_COMMAND'] || 'open $BCAT_ARGS "$BCAT_URL"'
|
|
17
36
|
|
18
37
|
pid = nil
|
19
38
|
begin
|
20
|
-
bcat = Bcat.new(fds)
|
39
|
+
bcat = Bcat.new(fds, options)
|
21
40
|
bcat.serve! do |sock|
|
22
41
|
pid =
|
23
42
|
fork do
|
data/lib/bcat.rb
CHANGED
@@ -2,7 +2,7 @@ require 'rack'
|
|
2
2
|
require 'bcat/kidgloves'
|
3
3
|
|
4
4
|
class Bcat
|
5
|
-
VERSION = '0.0.
|
5
|
+
VERSION = '0.0.1'
|
6
6
|
include Rack::Utils
|
7
7
|
|
8
8
|
def initialize(fds=[$stdin], config={})
|
@@ -20,26 +20,36 @@ class Bcat
|
|
20
20
|
|
21
21
|
def head
|
22
22
|
["<html>",
|
23
|
-
"<head><title
|
24
|
-
"<body
|
23
|
+
"<head><title>#{self[:title] || 'bcat'}</title></head>",
|
24
|
+
"<body>"].join
|
25
25
|
end
|
26
26
|
|
27
27
|
def foot
|
28
|
-
"</
|
28
|
+
"</body></html>"
|
29
|
+
end
|
30
|
+
|
31
|
+
def escape_js(string)
|
32
|
+
string = string.gsub(/['\\]/) { |char| "\\#{char}" }
|
33
|
+
string.gsub!(/\n/, '\n')
|
34
|
+
string
|
29
35
|
end
|
30
36
|
|
31
37
|
def each
|
32
38
|
yield "\n" * 1000
|
33
39
|
yield "<!DOCTYPE html>\n"
|
34
40
|
yield head
|
41
|
+
yield "<pre>" if !self[:html]
|
35
42
|
|
36
43
|
begin
|
37
44
|
@fds.each do |fd|
|
38
45
|
begin
|
39
46
|
while buf = fd.readpartial(4096)
|
40
|
-
|
41
|
-
|
42
|
-
|
47
|
+
if !self[:html]
|
48
|
+
buf = escape_html(buf)
|
49
|
+
buf.gsub!(/\n/, "<br>")
|
50
|
+
end
|
51
|
+
buf = escape_js(buf)
|
52
|
+
yield "<script>document.write('#{buf}');</script>"
|
43
53
|
end
|
44
54
|
rescue EOFError
|
45
55
|
ensure
|
@@ -48,6 +58,7 @@ class Bcat
|
|
48
58
|
end
|
49
59
|
end
|
50
60
|
|
61
|
+
yield "</pre>" if !self[:html]
|
51
62
|
yield foot
|
52
63
|
end
|
53
64
|
|
data/man/bcat.1.ronn
CHANGED
@@ -3,13 +3,23 @@ bcat(1) -- browser cat
|
|
3
3
|
|
4
4
|
## SYNOPSIS
|
5
5
|
|
6
|
-
`bcat
|
7
|
-
`bcat` <file>... [-]<br>
|
6
|
+
`bcat` [-ht] [<file>...]<br>
|
8
7
|
|
9
8
|
## DESCRIPTION
|
10
9
|
|
11
10
|
The `bcat` utility reads from standard input, or one or more <file>s, and writes
|
12
|
-
output to a web browser progressively.
|
11
|
+
output to a web browser progressively. A <file> may be '-', in which case
|
12
|
+
standard input is concatenated at the position specified.
|
13
|
+
|
14
|
+
* `-h`, `--html`:
|
15
|
+
Do not HTML encode input. By default, `bcat` assumes input is plain text
|
16
|
+
and entity encodes any `<` or `&` characters, converts raw end-of-line
|
17
|
+
characters (`\n`) to `<br>` tags, and wraps output in a `<pre>` block. The
|
18
|
+
`--html` option disables all of these conversions, causing the input text
|
19
|
+
to be written directly as HTML.
|
20
|
+
* `-t`, `--title`=<text>:
|
21
|
+
Use <text> as the page `<title>`. By default, the path to the current working
|
22
|
+
directory is used as the title.
|
13
23
|
|
14
24
|
## ENVIRONMENT
|
15
25
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bcat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ryan Tomayko
|
@@ -41,6 +41,7 @@ extensions: []
|
|
41
41
|
extra_rdoc_files:
|
42
42
|
- COPYING
|
43
43
|
files:
|
44
|
+
- README
|
44
45
|
- Rakefile
|
45
46
|
- bcat.gemspec
|
46
47
|
- bin/bcat
|