goog 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/bin/goog +17 -3
  2. data/lib/goog.rb +1 -1
  3. data/vim/goog.vim +22 -0
  4. metadata +2 -1
data/bin/goog CHANGED
@@ -6,6 +6,7 @@ require 'yaml'
6
6
  require 'uri'
7
7
  require 'optparse'
8
8
 
9
+
9
10
  options = {}
10
11
  OptionParser.new do |opts|
11
12
  opts.banner = "Usage: goog [options] [query]"
@@ -29,6 +30,13 @@ END
29
30
  opts.on("-d", '--date-range [DATE RANGE]', 'Show results for date range. See below for options.') {|dr| options[:date_range] = dr }
30
31
  opts.on("-n", '--num-pages [NUM PAGES]', 'Show NUM PAGES pages of results') {|pages| options[:pages] = pages.to_i }
31
32
  opts.on("-c", '--color', 'Force color output') {options[:color] = true}
33
+ opts.on("-v", '--vim', 'Open results in Vim and bind <leader>o to open URL on or after cursor') {
34
+ require 'tempfile'
35
+ options[:vim] = true
36
+ $vimscript_file = File.expand_path(File.join(File.dirname(__FILE__), '..', 'vim', 'goog.vim'))
37
+ $tempfile = Tempfile.new('goog')
38
+ $stdout = $tempfile
39
+ }
32
40
  end.parse!
33
41
  query = ARGV.join(' ')
34
42
  unless query
@@ -73,18 +81,24 @@ end
73
81
  end
74
82
  end
75
83
  number = (page - 1) * 10 + (index + 1)
76
- res = if STDOUT.tty? || options[:color]
84
+ res = if !options[:vim] && (STDOUT.tty? || options[:color])
77
85
  ["#{number}. \e[36m#{title}\e[0m", excerpt, "\e[35m#{link }\e[0m"]
78
86
  else
79
87
  ["#{number}. #{title}", excerpt, link]
80
88
  end
81
- puts res.compact
82
- puts
89
+ $stdout.puts res.compact
90
+ $stdout.puts
83
91
  }
92
+
84
93
  # find next page link
85
94
  # <a href="/search?q=why+the+lucky+stiff&amp;hl=en&amp;ie=UTF-8&amp;prmd=ivns&amp;ei=K6akT9bRBeaM6QHjifmwBA&amp;start=10&amp;sa=N" style="text-align:left"><span style="display:block;margin-left:53px">Next</span></a>
95
+
86
96
  next_page_href = (nextspan = doc.at("//span[contains(child::text(),'Next')]")) && nextspan.parent[:href]
87
97
  query = next_page_href
88
98
  end
89
99
 
100
+ if options[:vim]
101
+ $stdout.close
102
+ exec "vim -S #$vimscript_file #{$tempfile.path}"
103
+ end
90
104
 
data/lib/goog.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Goog
2
- VERSION = '0.0.8'
2
+ VERSION = '0.0.9'
3
3
  end
data/vim/goog.vim ADDED
@@ -0,0 +1,22 @@
1
+ syntax region h1 start="^\d\+\." end="\($\)"
2
+ syntax region href start="^http:" end="\($\)"
3
+ highlight link h1 Identifier
4
+ highlight link href Constant
5
+ hi Identifier term=NONE cterm=NONE gui=NONE ctermfg=LightCyan
6
+ hi Constant term=NONE cterm=NONE gui=NONE ctermfg=Magenta
7
+
8
+ let s:http_link_pattern = 'https\?:[^ >)\]]\+'
9
+ let g:browser_command = system("echo -n $(which gnome-open || which open)")
10
+ func! s:open_href_under_cursor()
11
+ let res = search(s:http_link_pattern, 'cw')
12
+ if res != 0
13
+ let href = matchstr(expand("<cWORD>") , s:http_link_pattern)
14
+ let command = g:browser_command . " '" . shellescape(href) . "' "
15
+ echom command
16
+ call system(command)
17
+ end
18
+ endfunc
19
+
20
+ nnoremap <leader>o :call <SID>open_href_under_cursor()<CR>
21
+
22
+ " http://www.padrinorb.com/pages/why
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.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -37,6 +37,7 @@ extra_rdoc_files: []
37
37
  files:
38
38
  - bin/goog
39
39
  - lib/goog.rb
40
+ - vim/goog.vim
40
41
  homepage: https://github.com/danchoi/goog
41
42
  licenses: []
42
43
  post_install_message: