goog 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/bin/goog +28 -3
  2. data/lib/goog.rb +1 -1
  3. data/plugin/goog.vim +94 -0
  4. metadata +3 -3
  5. data/vim/goog.vim +0 -51
data/bin/goog CHANGED
@@ -6,7 +6,8 @@ require 'yaml'
6
6
  require 'uri'
7
7
  require 'optparse'
8
8
 
9
-
9
+ $vimscript_file = File.expand_path(File.join(File.dirname(__FILE__), '..', 'plugin', 'goog.vim'))
10
+ orig_query = "query: #{ARGV.join(' ')}\n\n"
10
11
  options = {}
11
12
  OptionParser.new do |opts|
12
13
  opts.banner = "Usage: goog [options] [query]"
@@ -25,6 +26,23 @@ VIM KEY MAPPINGS
25
26
  <leader>o open URL on or after cursor in default external web browser
26
27
  <leader>O open URL on or after cursor in split Vim window using elinks, links, or lynx
27
28
 
29
+ VIM PLUGIN COMMANDS
30
+
31
+ :Goog [query]
32
+
33
+ where query is any of the flags and arguments you can pass to the command
34
+ line version, except for -v.
35
+
36
+ goog will run the Google search and print matches with syntax coloring in a
37
+ split Vim buffer.
38
+
39
+ In the GoogSearchResults buffer:
40
+
41
+ CTRL-j jumps to the next URL
42
+ CTRL-k jumps to the previous URL
43
+ <leader>o open URL on or after cursor in default external web browser
44
+ <leader>O open URL on or after cursor in split Vim window using elinks, links, or lynx
45
+
28
46
  goog #{Goog::VERSION}
29
47
  http://github.com/danchoi/goog
30
48
  Author: Daniel Choi <dhchoi@gmail.com>
@@ -37,22 +55,29 @@ END
37
55
  opts.on("-v", '--vim', 'Open results in Vim and bind <leader>o to open URL on or after cursor') {
38
56
  require 'tempfile'
39
57
  options[:vim] = true
40
- $vimscript_file = File.expand_path(File.join(File.dirname(__FILE__), '..', 'vim', 'goog.vim'))
41
58
  $tempfile = Tempfile.new('goog')
42
59
  $stdout = $tempfile
43
60
  }
61
+ opts.on("-i", '--install-plugin', 'Install Goog as a Vim plugin') {
62
+ puts "Installing goog.vim into your ~/.vim/plugin directory."
63
+ `cp #{$vimscript_file} #{ENV['HOME']}/.vim/plugin/`
64
+ puts "Done. Type goog -h for Vim commands."
65
+ exit
66
+ }
44
67
  end.parse!
45
68
  query = ARGV.join(' ')
46
69
  unless query
47
70
  abort "Please provide a search query"
48
71
  end
49
72
 
73
+ $stdout.puts orig_query
50
74
  unless `which tidy` =~ /tidy/
51
75
  abort "No tidy found. Please install tidy."
52
76
  end
53
77
  if RUBY_VERSION !~ /^1.9/
54
78
  abort "Requires Ruby 1.9"
55
79
  end
80
+
56
81
  query = "/search?q=#{CGI.escape query}"
57
82
  if options[:date_range]
58
83
  query += "&as_qdr=#{options[:date_range]}"
@@ -103,6 +128,6 @@ end
103
128
 
104
129
  if options[:vim]
105
130
  $stdout.close
106
- exec "vim -S #$vimscript_file #{$tempfile.path}"
131
+ exec "vim -S #$vimscript_file -c 'call g:Goog_set_up_search_results_buffer()' #{$tempfile.path}"
107
132
  end
108
133
 
data/lib/goog.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Goog
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  end
data/plugin/goog.vim ADDED
@@ -0,0 +1,94 @@
1
+ " Vim script that makes Vim a search results browser
2
+ " http://github.com/danchoi/goog
3
+ " Maintainer: Daniel Choi <dhchoi@gmail.com>
4
+ " License: MIT License (c) 2012 Daniel Choi
5
+
6
+
7
+ let s:http_link_pattern = '^https\?:[^ >)\]]\+'
8
+
9
+ let g:gui_web_browser = system("echo -n $(which gnome-open || which open)")
10
+ if ! exists("g:text_web_browser")
11
+ if executable("elinks")
12
+ let g:text_web_browser = 'elinks -dump -no-numbering'
13
+ elseif executable("lynx")
14
+ let g:text_web_browser = 'lynx -dump -nonumbers'
15
+ elseif executable("links")
16
+ let g:text_web_browser = 'links -dump'
17
+ endif
18
+ end
19
+
20
+
21
+ let s:web_page_bufname = "GoogWeb"
22
+
23
+ func! s:open_href_under_cursor(text_browser)
24
+ let res = search(s:http_link_pattern, 'cw')
25
+ if res != 0
26
+ let href = matchstr(expand("<cWORD>") , s:http_link_pattern)
27
+ if a:text_browser == 0
28
+ let command = g:gui_web_browser . " " . shellescape(href) . " "
29
+ call system(command)
30
+ else
31
+ let command = g:text_web_browser . ' ' . shellescape(href) . " "
32
+ echom command
33
+ let result = system(command)
34
+ if bufexists(s:web_page_bufname) && bufwinnr(s:web_page_bufname) != -1
35
+ exec bufwinnr(s:web_page_bufname)."wincmd w "
36
+ else
37
+ exec "split ".s:web_page_bufname
38
+ endif
39
+ silent! put! =result
40
+ silent! 1put! ='URL: '.href
41
+ silent! 2put! =''
42
+ setlocal buftype=nofile
43
+ normal 1G
44
+ endif
45
+ end
46
+ endfunc
47
+
48
+ func! s:find_next_link(backward)
49
+ let n = 0
50
+ " don't wrap
51
+ if a:backward == 1
52
+ normal lb
53
+ let result = search(s:http_link_pattern, 'Wb')
54
+ else
55
+ let result = search(s:http_link_pattern, 'W')
56
+ endif
57
+ if (result == 0)
58
+ return ""
59
+ end
60
+ return
61
+ endfunc
62
+
63
+
64
+ func! g:Goog_set_up_search_results_buffer()
65
+ syntax region h1 start="^\d\+\." end="\($\)"
66
+ syntax region href start="^https\?:" end="\($\)"
67
+ highlight link h1 Identifier
68
+ highlight link href Constant
69
+ hi Identifier term=NONE cterm=NONE gui=NONE ctermfg=LightCyan
70
+ hi Constant term=NONE cterm=NONE gui=NONE ctermfg=Magenta
71
+ nnoremap <buffer> <leader>o :call <SID>open_href_under_cursor(0)<CR>
72
+ nnoremap <buffer> <leader>O :call <SID>open_href_under_cursor(1)<CR>
73
+ noremap <buffer> <c-j> :call <SID>find_next_link(0)<CR>
74
+ noremap <buffer> <c-k> :call <SID>find_next_link(1)<CR>
75
+ endfunc
76
+
77
+ func! s:run_Goog_search(query)
78
+ let g:Goog_running_in_vim = 1
79
+ if !executable("goog")
80
+ echom "You don't have goog installed. Please gem install goog and try again."
81
+ finish
82
+ endif
83
+ let res=system("goog ".shellescape(a:query))
84
+ exec "split GoogSearchResults"
85
+ silent! put! =res
86
+ silent! 1put! ='query: 'query
87
+ silent! 2put! =''
88
+ setlocal buftype=nofile
89
+ normal 1G
90
+ call g:Goog_set_up_search_results_buffer()
91
+ endfunc
92
+
93
+ command -nargs=* Goog call <SID>run_Goog_search(<q-args>)
94
+
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.1.3
4
+ version: 0.1.4
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-06 00:00:00.000000000 Z
12
+ date: 2012-05-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -37,7 +37,7 @@ extra_rdoc_files: []
37
37
  files:
38
38
  - bin/goog
39
39
  - lib/goog.rb
40
- - vim/goog.vim
40
+ - plugin/goog.vim
41
41
  homepage: https://github.com/danchoi/goog
42
42
  licenses: []
43
43
  post_install_message:
data/vim/goog.vim DELETED
@@ -1,51 +0,0 @@
1
- syntax region h1 start="^\d\+\." end="\($\)"
2
- syntax region href start="^https\?:" 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
-
10
- let g:gui_web_browser = system("echo -n $(which gnome-open || which open)")
11
- if ! exists("g:text_web_browser")
12
- if executable("elinks")
13
- let g:text_web_browser = 'elinks -dump -no-numbering'
14
- elseif executable("lynx")
15
- let g:text_web_browser = 'lynx -dump -nonumbers'
16
- elseif executable("links")
17
- let g:text_web_browser = 'links -dump'
18
- endif
19
- end
20
-
21
-
22
- let s:web_page_bufname = "GoogBrowser"
23
- func! s:open_href_under_cursor(text_browser)
24
- let res = search(s:http_link_pattern, 'cw')
25
- if res != 0
26
- let href = matchstr(expand("<cWORD>") , s:http_link_pattern)
27
- if a:text_browser == 0
28
- let command = g:gui_web_browser . " " . shellescape(href) . " "
29
- call system(command)
30
- else
31
- let command = g:text_web_browser . ' ' . shellescape(href) . " "
32
- echom command
33
- let result = system(command)
34
- if bufexists(s:web_page_bufname) && bufwinnr(s:web_page_bufname) != -1
35
- exec bufwinnr(s:web_page_bufname)."wincmd w"
36
- else
37
- exec "new ".s:web_page_bufname
38
- endif
39
- silent! put! =result
40
- silent! 1put! ='URL: '.href
41
- silent! 2put! =''
42
- setlocal buftype=nofile
43
- normal 1G
44
- endif
45
- end
46
- endfunc
47
-
48
- nnoremap <leader>o :call <SID>open_href_under_cursor(0)<CR>
49
- nnoremap <leader>O :call <SID>open_href_under_cursor(1)<CR>
50
-
51
- " http://www.padrinorb.com/pages/why