You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
% 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
The text was updated successfully, but these errors were encountered:
% 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):
The text was updated successfully, but these errors were encountered: