rtomayko / bcat Goto Github PK
View Code? Open in Web Editor NEWA pipe to browser utility
Home Page: http://rtomayko.github.com/bcat/
License: Other
A pipe to browser utility
Home Page: http://rtomayko.github.com/bcat/
License: Other
I'm wondering if it's possible to inject a css file, or control some of the html output through a command... I can try and work on it, not much of a ruby guy so would be a nice challenge :)
bcat breaks if I update rack, does 1.2 really break bcat beyond the dep?
% echo foo | env BCAT_COMMAND="echo >/dev/tty" bcat
[shows foo in my default browser as usual]
From browser.rb, it seems like the BCAT_COMMAND value is stored into @command, but @command isn't used.
Commenting out the "command = browser_command" so that the #{command} will call self.command works.
I've a patch below for this problem and the quoting problem (which I'll open a bug for after this):
--- /opt/local/lib/ruby/gems/1.8/gems/bcat-0.5.1/lib/bcat/browser.rb.original 2010-09-10 10:47:06.000000000 -0700
+++ /opt/local/lib/ruby/gems/1.8/gems/bcat-0.5.1/lib/bcat/browser.rb 2010-09-10 11:31:02.000000000 -0700
@@ -37,33 +37,39 @@
'gnome' => 'epiphany'
}
- def initialize(browser, command=ENV['BCAT_COMMAND'])
+ def initialize(browser, command=nil)
@browser = browser
- @command = command
+ @command = command || ENV['BCAT_COMMAND'] || command_for_browser(@browser)
end
+ # open a given url
def open(url)
- command = browser_command
- fork do
- [$stdin, $stdout].each { |fd| fd.close }
- exec "#{command} '#{shell_quote(url)}'"
- end
- end
-
- def command
- return @command if @command
- browser_command
+ # run the browser command with stdin, stdout, and stderr closed
+ system "#{@command} </dev/null >/dev/null 2>&1 #{shell_quote(url)}"
end
- def browser_command(browser=@browser)
- browser ||= 'default'
- browser = browser.downcase
- browser = ALIASES[browser] || browser
- COMMANDS[ENVIRONMENT][browser]
+ # return the command to run for a given browser
+ def command_for_browser(browser='default')
+ browser = ALIASES[browser] || browser.downcase
+ COMMANDS[ENVIRONMENT][browser] || COMMANDS[ENVIRONMENT]['default']
end
+ # return a given string quoted for a POSIX shell
def shell_quote(argument)
- arg = argument.to_s.gsub(/([\\'])/) { "\\" + $1 }
+ argument=argument.to_s
+ # if the argument is a simple, single word, leave it alone
+ if argument =~ /^[a-zA-Z0-9_+@%=,.\/\-]+$/
+ argument
+ else
+ # replace any backslashes with escaped versions
+ argument.gsub!(/(\\)/, "\\\\")
+ # single quotes cannot be quoted inside single quotes, so we
+ # end the single quoted string, put a double-quoted string containing a
+ # single quote, and then start a new single-quoted string. ugly, but works
+ argument.gsub!(/'/, %w{'"'"'})
+ # and wrap it in single quotes
+ "'#{argument}'"
+ end
end
end
end
AFAICT the second example in the README file should be
echo .. | bcat -T "window title"
while it is
echo .. | bcat -t "window title"
which has the effect of trying to load an unexisting file (with an unpretty error)
Hey Ryan,
I thought I'd share this little ZSH snippet for viewing man pages with formatting using bcat. It turns out this is actually quite tedious to achieve, because roff uses overprinting to achieve bold, rather than real ANSI bold escape sequences (a hangover from daisy-wheel printer days!).
function bman {
colors
local bold=$'\\(.\\)\b\\1'
local ul=$'_\b\\(.\\)'
man ${@} | sed "s/${bold}/$fg_bold[blue]\1$reset_color/g;s/${ul}/$fg_bold[red]\1$reset_color/g" | bcat
}
Hope this is useful to someone.
Sorry I can't be more precise. I'm on OS X 10.5.8, with Ruby 1.8.6. I installed it with 'sudo gem install bcat' and now I'm getting the following error whenever I attempt to run bcat, even just on its own:
/Library/Ruby/Gems/1.8/gems/rack-1.2.1/lib/rack/utils.rb:138:in `union': can't convert Array into String (TypeError)
from /Library/Ruby/Gems/1.8/gems/rack-1.2.1/lib/rack/utils.rb:138
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
from /Library/Ruby/Gems/1.8/gems/bcat-0.5.0/lib/bcat/reader.rb:1
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
from /Library/Ruby/Gems/1.8/gems/bcat-0.5.0/lib/bcat.rb:2
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
from /Library/Ruby/Gems/1.8/gems/bcat-0.5.0/bin/bcat:49
from /usr/bin/bcat:19:in `load'
from /usr/bin/bcat:19
The first Vim mapping is:
:map ,pm :!markdown % |bcat
This didn't work for me. However this did:
:map ,pm :!markdown % \|bcat<CR>
You could also use <Bar>
on the RHS instead of \|
.
If at least btee can allow multiple connections, I can do things such as irb|btee
and other people can watch what I do in btee.
That'd be awesome. :D
bcat seems to have trouble capturing the stdout from bundle exec ,
the browser page just hangs never responding and stdout appears on the console like normal.
Related to #17: If I can specify the port, then i can use something like irb|btee --multiple --port=8000
(or w/e flag names you use) and people could connect on port 8000 to watch what i'm doing (AND I wouldn't need to adjust port forwarding every time, as I'd have to do now).
jruby doesn't support fork
, any preferred alternative?
Hi,
Could you create a LICENSE file containing your license ?
It's quite difficult to understand what license do you use.
Regards
I've just pushed my local git repo to github so you've a bit of history for ansi2html.sh
http://github.com/pixelb/scripts/blob/master/scripts/ansi2html.sh
cheers,
Pádraig.
First of all thank you for this great tool:
actually i use a2h and there is no spaces translation, convert spaces to
?
bcat seems to fail when calling the browser with a path containing spaces.
For instance:
amon:50 Sources dom$ git log -p --color |bcat
The file /Users/foo/Documents/Personnel/21 Blog/50 Sources/Sources does not exist.
If you add quotes around the url when executing the comand it seems to work fine. I just changed line 49 of browser.rb from:
exec "#{command} #{shell_quote(url)}"
to :
exec "#{command} '#{shell_quote(url)}'"
I'm using the gem v. 0.5.0 but HEAD seems to have the same issue.
Hope this helps.
The shell_quote method in browser.rb replaces any single-quotes (') with a backslash-escaped single-quote.
This doesn't actually work: there is no way to quote a single-quote inside a single-quoted string in a POSIX shell.
I opened another bug for the BCAT_COMMAND environment variable being ignored; it also includes a new shell_quote method that escapes single quotes correctly.
For example, shell_quote("foo'bar").inspect returns "'foo'"'"'bar'" which is correctly parsed by a POSIX shell.
Heres the function below:
# return a given string quoted for a POSIX shell
def shell_quote(argument)
argument=argument.to_s
# if the argument is a simple, single word, leave it alone
if argument =~ /^[a-zA-Z0-9_+@%=,.\/\-]+$/
argument
else
# replace any backslashes with escaped versions
argument.gsub!(/(\\)/, "\\\\")
# single quotes cannot be quoted inside single quotes, so we
# end the single quoted string, put a double-quoted string containing a
# single quote, and then start a new single-quoted string. ugly, but works
argument.gsub!(/'/, %w{'"'"'})
# and wrap it in single quotes
"'#{argument}'"
end
end
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.