bcat 0.5.2 → 0.6.0

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.
@@ -0,0 +1,10 @@
1
+ RELEASING
2
+
3
+ 1. Change Bcat::VERSION in lib/bcat.rb
4
+ 2. rake bcat.gemspec
5
+ 3. rake package
6
+ 4. git add lib/bcat.rb bcat.gemspec
7
+ 5. git commit -m "0.5.3 release"
8
+ 6. git tag v0.5.3
9
+ 7. git push origin master v0.5.3
10
+ 8. gem push bcat-0.5.3.gem
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'bcat'
3
- s.version = '0.5.2'
4
- s.date = '2010-08-23'
3
+ s.version = '0.6.0'
4
+ s.date = '2011-02-21'
5
5
 
6
6
  s.description = "pipe to browser utility"
7
7
  s.summary =
@@ -17,6 +17,7 @@ Gem::Specification.new do |s|
17
17
  COPYING
18
18
  INSTALLING
19
19
  README
20
+ RELEASING
20
21
  Rakefile
21
22
  bcat.gemspec
22
23
  bin/a2h
data/bin/a2h CHANGED
@@ -9,6 +9,7 @@ $stdout.sync = true
9
9
 
10
10
  ARGV.push '-' if ARGV.empty?
11
11
 
12
- reader = Bcat::Reader.new(ARGV.to_a)
12
+ reader = Bcat::Reader.new(false, ARGV.to_a)
13
+ reader.open
13
14
  filter = Bcat::ANSI.new(reader)
14
15
  filter.each { |text| $stdout.write(text) }
data/bin/bcat CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
- #/ Usage: bcat [-ht] [-a] [-b <browser>] [-T <title>] [<file>]...
2
+ #/ Usage: bcat [-htp] [-a] [-b <browser>] [-T <title>] [<file>]...
3
+ #/ bcat [-htp] [-a] [-b <browser>] [-T <title>] -c command...
3
4
  #/ btee <options> [<file>]...
4
5
  #/ Pipe to browser utility. Read standard input, possibly one or more <file>s,
5
6
  #/ and write concatenated / formatted output to browser. When invoked as btee,
@@ -15,7 +16,9 @@
15
16
  #/ -t, --text input is unencoded text
16
17
  #/
17
18
  #/ Misc options:
18
- #/ -d, --debug enable verbose debug logging on stderr
19
+ #/ -c, --command read the standard output of command
20
+ #/ -p, --persist serve until interrupted, allowing reload
21
+ #/ -d, --debug enable verbose debug logging on stderr
19
22
  require 'optparse'
20
23
 
21
24
  options = {
@@ -25,6 +28,8 @@ options = {
25
28
  :title => nil,
26
29
  :browser => (ENV['BCAT_BROWSER'].to_s.size > 0 ? ENV['BCAT_BROWSER'] : 'default'),
27
30
  :ansi => false,
31
+ :persist => false,
32
+ :command => false,
28
33
  :debug => false,
29
34
  :tee => !!($0 =~ /tee$/)
30
35
  }
@@ -38,6 +43,8 @@ ARGV.options do |argv|
38
43
  argv.on('-b', '--browser=v') { |app| options[:browser] = app }
39
44
  argv.on('-T', '--title=v') { |text| options[:title] = text }
40
45
  argv.on('-a', '--ansi') { options[:ansi] = true }
46
+ argv.on('-p', '--persist') { options[:persist] = true }
47
+ argv.on('-c', '--command') { options[:command] = true }
41
48
  argv.on('-d', '--debug') { options[:debug] = true }
42
49
  argv.on('--host=v') { |addr| options[:Host] = addr }
43
50
  argv.on('--port=v') { |port| options[:Port] = port.to_i }
@@ -6,14 +6,14 @@ require 'bcat/server'
6
6
  require 'bcat/browser'
7
7
 
8
8
  class Bcat
9
- VERSION = '0.5.2'
9
+ VERSION = '0.6.0'
10
10
  include Rack::Utils
11
11
 
12
12
  attr_reader :format
13
13
 
14
- def initialize(files=[], config={})
14
+ def initialize(args=[], config={})
15
15
  @config = {:Host => '127.0.0.1', :Port => 8091}.merge(config)
16
- @reader = Bcat::Reader.new(files)
16
+ @reader = Bcat::Reader.new(@config[:command], args)
17
17
  @format = @config[:format]
18
18
  end
19
19
 
@@ -39,6 +39,8 @@ class Bcat
39
39
  end
40
40
 
41
41
  def assemble
42
+ @reader.open
43
+
42
44
  @format = @reader.sniff if @format.nil?
43
45
 
44
46
  @filter = @reader
@@ -103,8 +105,10 @@ class Bcat
103
105
  end
104
106
 
105
107
  def close
106
- notice "closing with interrupt"
107
- raise Interrupt, "connection closed"
108
+ unless @config[:persist]
109
+ notice "closing with interrupt"
110
+ raise Interrupt, "connection closed"
111
+ end
108
112
  end
109
113
 
110
114
  def notice(message)
@@ -43,16 +43,15 @@ class Bcat
43
43
  end
44
44
 
45
45
  def open(url)
46
- command = browser_command
47
46
  fork do
48
47
  $stdin.close
49
- exec "#{command} '#{shell_quote(url)}'"
48
+ exec "#{command} #{shell_quote(url)}"
49
+ exit! 128
50
50
  end
51
51
  end
52
52
 
53
53
  def command
54
- return @command if @command
55
- browser_command
54
+ @command || browser_command
56
55
  end
57
56
 
58
57
  def browser_command(browser=@browser)
@@ -63,7 +62,7 @@ class Bcat
63
62
  end
64
63
 
65
64
  def shell_quote(argument)
66
- arg = argument.to_s.gsub(/([\\'])/) { "\\" + $1 }
65
+ '"' + argument.to_s.gsub(/([\\"`$])/) { "\\" + $1 } + '"'
67
66
  end
68
67
  end
69
68
  end
@@ -4,25 +4,38 @@ class Bcat
4
4
  # ARGF style multi-file streaming interface. Input is read with IO#readpartial
5
5
  # to avoid buffering.
6
6
  class Reader
7
- attr_reader :files
7
+ attr_reader :is_command
8
+ attr_reader :args
8
9
  attr_reader :fds
9
10
 
10
- def initialize(files=[])
11
- @files = files
12
- @fds =
13
- files.map do |f|
14
- if f == '-'
15
- $stdin
16
- else
17
- File.open(f, 'rb')
18
- end
19
- end
11
+ def initialize(is_command, args=[])
12
+ @is_command = is_command
13
+ @args = args
14
+ end
15
+
16
+ def open
17
+ @fds = is_command ? open_command : open_files
20
18
  @buf = []
21
19
  end
22
20
 
21
+ def open_command
22
+ [IO.popen(args.join(' '), 'rb')]
23
+ end
24
+
25
+ def open_files
26
+ args.map do |f|
27
+ if f == '-'
28
+ $stdin
29
+ else
30
+ File.open(f, 'rb')
31
+ end
32
+ end
33
+ end
34
+
23
35
  def each
24
36
  yield @buf.shift while @buf.any?
25
37
  while fd = fds.first
38
+ fds.shift and next if fd.closed?
26
39
  fd.sync = true
27
40
  begin
28
41
  while buf = fd.readpartial(4096)
@@ -3,7 +3,8 @@ bcat(1) -- browser cat
3
3
 
4
4
  ## SYNOPSIS
5
5
 
6
- `bcat` [-htad] [<file>...]<br>
6
+ `bcat` [-htapd] [<file>...]<br>
7
+ `bcat` [-htapd] -c <command>...<br>
7
8
  `btee` [-htad] [<file>...]
8
9
 
9
10
  ## DESCRIPTION
@@ -46,13 +47,23 @@ with these options:
46
47
  entire output is wrapped in a `<pre>`.
47
48
 
48
49
  * `-h`, `--html`:
49
- The input is already HTML encoded. Under this mode, bcat passes input
50
+ The input is already HTML encoded. Under this mode, `bcat` passes input
50
51
  through to the browser mostly unmodified. The input may be a full HTML
51
52
  document, or it may be an HTML fragment. `bcat` outputs `<html>`, `<head>`,
52
53
  and `<body>` elements even if they are not included in the input.
53
54
 
54
55
  Miscellaneous options:
55
56
 
57
+ * `-c`, `--command`:
58
+ Interpret the remaining options as a command to be run whose output should
59
+ be piped into the web browser.
60
+
61
+ * `-p`, `--persist`:
62
+ Have `bcat` serve requests until it is interrupted. Reloading the page
63
+ in the browser will cause `bcat` to re-read the files (or re-run the command
64
+ if used with the `--command` option). Standard input can only be read once
65
+ and will produce no content on subsequent requests.
66
+
56
67
  * `-d`, `--debug`:
57
68
  Turn on verbose debug logging to standard error. Include this output when
58
69
  reporting defects if applicable.
@@ -92,6 +103,10 @@ For previewing HTML:
92
103
  mustache < template.mustache |bcat
93
104
  pygmentize -Ofull,style=colorful -f html main.c |bcat
94
105
 
106
+ Regenerate the content each time the page is reloaded:
107
+
108
+ bcat -pc markdown README.md
109
+
95
110
  As a simple man pager:
96
111
 
97
112
  export MANPAGER='col -b |bcat'
@@ -3,7 +3,8 @@ bcat(1) -- browser cat
3
3
 
4
4
  ## SYNOPSIS
5
5
 
6
- `bcat` [-htad] [<file>...]<br>
6
+ `bcat` [-htapd] [<file>...]<br>
7
+ `bcat` [-htapd] -c <command>...<br>
7
8
  `btee` [-htad] [<file>...]
8
9
 
9
10
  ## DESCRIPTION
@@ -46,13 +47,23 @@ with these options:
46
47
  entire output is wrapped in a `<pre>`.
47
48
 
48
49
  * `-h`, `--html`:
49
- The input is already HTML encoded. Under this mode, bcat passes input
50
+ The input is already HTML encoded. Under this mode, `bcat` passes input
50
51
  through to the browser mostly unmodified. The input may be a full HTML
51
52
  document, or it may be an HTML fragment. `bcat` outputs `<html>`, `<head>`,
52
53
  and `<body>` elements even if they are not included in the input.
53
54
 
54
55
  Miscellaneous options:
55
56
 
57
+ * `-c`, `--command`:
58
+ Interpret the remaining options as a command to be run whose output should
59
+ be piped into the web browser.
60
+
61
+ * `-p`, `--persist`:
62
+ Have `bcat` serve requests until it is interrupted. Reloading the page
63
+ in the browser will cause `bcat` to re-read the files (or re-run the command
64
+ if used with the `--command` option). Standard input can only be read once
65
+ and will produce no content on subsequent requests.
66
+
56
67
  * `-d`, `--debug`:
57
68
  Turn on verbose debug logging to standard error. Include this output when
58
69
  reporting defects if applicable.
@@ -92,6 +103,10 @@ For previewing HTML:
92
103
  mustache < template.mustache |bcat
93
104
  pygmentize -Ofull,style=colorful -f html main.c |bcat
94
105
 
106
+ Regenerate the content each time the page is reloaded:
107
+
108
+ bcat -pc markdown README.md
109
+
95
110
  As a simple man pager:
96
111
 
97
112
  export MANPAGER='col -b |bcat'
@@ -2,4 +2,11 @@ require 'contest'
2
2
  require 'bcat/browser'
3
3
 
4
4
  class BrowserTest < Test::Unit::TestCase
5
+
6
+ setup { @browser = Bcat::Browser.new('default', nil) }
7
+
8
+ test 'shell quotes double-quotes, backticks, and parameter expansion' do
9
+ assert_equal "\"http://example.com/\\\"/\\$(echo oops)/\\`echo howdy\\`\"",
10
+ @browser.shell_quote("http://example.com/\"/$(echo oops)/`echo howdy`")
11
+ end
5
12
  end
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: 15
4
+ hash: 7
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 5
9
- - 2
10
- version: 0.5.2
8
+ - 6
9
+ - 0
10
+ version: 0.6.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ryan Tomayko
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-23 00:00:00 -07:00
18
+ date: 2011-02-21 00:00:00 -08:00
19
19
  default_executable: bcat
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -48,6 +48,7 @@ files:
48
48
  - COPYING
49
49
  - INSTALLING
50
50
  - README
51
+ - RELEASING
51
52
  - Rakefile
52
53
  - bcat.gemspec
53
54
  - bin/a2h