goog 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/goog +35 -10
- data/lib/goog.rb +1 -1
- metadata +3 -3
data/bin/goog
CHANGED
@@ -52,12 +52,10 @@ END
|
|
52
52
|
opts.on("-d", '--date-range [DATE RANGE]', 'Show results for date range. See below for options.') {|dr| options[:date_range] = dr }
|
53
53
|
opts.on("-n", '--num-pages [NUM PAGES]', 'Show NUM PAGES pages of results') {|pages| options[:pages] = pages.to_i }
|
54
54
|
opts.on("-c", '--color', 'Force color output') {options[:color] = true}
|
55
|
-
opts.on("-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
$stdout = $tempfile
|
60
|
-
}
|
55
|
+
opts.on("-x", '--expand', 'Expand all results into web page text') { options[:expand] = true }
|
56
|
+
opts.on("-e", '--elinks', 'Open results in elinks') { options[:elinks] = true }
|
57
|
+
opts.on("-l", '--less', 'Open results in less') { options[:less] = true }
|
58
|
+
opts.on("-v", '--vim', 'Open results in Vim and bind <leader>o to open URL on or after cursor') { options[:vim] = true }
|
61
59
|
opts.on("-i", '--install-plugin', 'Install Goog as a Vim plugin') {
|
62
60
|
puts "Installing goog.vim into your ~/.vim/plugin directory."
|
63
61
|
`cp #{$vimscript_file} #{ENV['HOME']}/.vim/plugin/`
|
@@ -74,6 +72,13 @@ END
|
|
74
72
|
exit
|
75
73
|
}
|
76
74
|
end.parse!
|
75
|
+
|
76
|
+
if options[:elinks] || options[:vim] || options[:less]
|
77
|
+
require 'tempfile'
|
78
|
+
$tempfile = Tempfile.new('goog')
|
79
|
+
$stdout = $tempfile
|
80
|
+
end
|
81
|
+
|
77
82
|
query = ARGV.join(' ')
|
78
83
|
unless query
|
79
84
|
abort "Please provide a search query"
|
@@ -88,6 +93,7 @@ query = "/search?q=#{CGI.escape query}"
|
|
88
93
|
if options[:date_range]
|
89
94
|
query += "&as_qdr=#{options[:date_range]}"
|
90
95
|
end
|
96
|
+
pages = []
|
91
97
|
(1..(options[:pages] || 1)).each do |page|
|
92
98
|
if query.nil?
|
93
99
|
exit
|
@@ -116,13 +122,22 @@ end
|
|
116
122
|
end
|
117
123
|
end
|
118
124
|
number = (page - 1) * 10 + (index + 1)
|
119
|
-
res = if
|
120
|
-
|
125
|
+
res = if options[:elinks]
|
126
|
+
%Q| <p>#{number}. <strong>#{title}</strong><br/>#{excerpt}<br/><a href='#{link}'>#{link}</a></p> |
|
127
|
+
elsif !options[:vim] && (STDOUT.tty? || options[:less] || options[:color])
|
128
|
+
["#{number}. \e[36m#{title}\e[0m", excerpt, "\e[35m#{link }\e[0m"].compact
|
121
129
|
else
|
122
|
-
["#{number}. #{title}", excerpt, link]
|
130
|
+
["#{number}. #{title}", excerpt, link].compact
|
123
131
|
end
|
124
|
-
|
132
|
+
puts '-' * 80
|
133
|
+
$stdout.puts res
|
125
134
|
$stdout.puts
|
135
|
+
if options[:expand]
|
136
|
+
$stderr.puts "Fetching #{title}: #{link}"
|
137
|
+
puts "#{title}: #{link}"
|
138
|
+
puts `elinks -dump -no-numbering '#{link}'`
|
139
|
+
end
|
140
|
+
puts
|
126
141
|
}
|
127
142
|
|
128
143
|
# find next page link
|
@@ -137,3 +152,13 @@ if options[:vim]
|
|
137
152
|
exec "vim -S #$vimscript_file -c 'call g:Goog_set_up_search_results_buffer()' #{$tempfile.path}"
|
138
153
|
end
|
139
154
|
|
155
|
+
if options[:less]
|
156
|
+
$stdout.close
|
157
|
+
exec "less -R #{$tempfile.path}"
|
158
|
+
end
|
159
|
+
|
160
|
+
if options[:elinks]
|
161
|
+
$stdout.close
|
162
|
+
exec "mv #{$tempfile.path}{,.html} && elinks #{$tempfile.path}.html"
|
163
|
+
end
|
164
|
+
|
data/lib/goog.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: goog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
@@ -58,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
58
|
version: '0'
|
59
59
|
requirements: []
|
60
60
|
rubyforge_project: goog
|
61
|
-
rubygems_version: 1.8.
|
61
|
+
rubygems_version: 1.8.23
|
62
62
|
signing_key:
|
63
63
|
specification_version: 3
|
64
64
|
summary: Simple command line interface to Google search
|