This repository has been archived by the owner on Jun 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
webrc.rb
112 lines (96 loc) · 2.07 KB
/
webrc.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env ruby
# DEVELOPED BY RITVIK CHOUDHARY
system = `uname -s`
@search = ARGV
@query = ''
case system
when 'Darwin', "Darwin\n"
@open_command = 'open'
else
@open_command = 'xdg-open'
end
def search_query
@search.each do |word|
add_to_query(word)
end
system "#{@open_command} https://www.google.com/search?q=\"#{@query}\""
end
def search_stack
@search.delete(@search.first)
@search.each do |word|
if word == @search.last
@query << word
else
@query << "#{word}+"
end
end
system "#{@open_command} http://stackoverflow.com/search?q=#{@query}"
end
def search_youtube
@search.delete(@search.first)
@search.each do |word|
add_to_query(word)
end
system "#{@open_command} https://www.youtube.com/results?search_query=\"#{@query}\""
end
def search_images
@search.delete(@search.first)
@search.each do |word|
add_to_query(word)
end
system "#{@open_command} \"https://www.google.com/search?q=#{@query}&tbm=isch\""
end
def search_wiki
@search.delete(@search.first)
@search.each do |word|
if word == @search.last
@query << word
else
@query << "#{word}+"
end
end
system "#{@open_command} http://www.wikipedia.org/w/index.php?search=\"#{@query}\""
end
def search_wolfram
@search.delete(@search.first)
@search.each do |word|
add_to_query(word)
end
system "#{@open_command} http://www.wolframalpha.com/input/?i=\"#{@query}\""
end
def add_to_query(word)
if word == @search.last
@query << word
else
@query << "#{word} "
end
end
def usage
puts <<-USAGE
webrc - The internet at the doorstep of your Command Line!
Usage:
webrc [query]
webrc -i [query]
webrc -yt [query]
webrc -wiki/--wikipedia [query]
webrc -so/--stack [query]
webrc -wa/--wolfram [query]
webrc -h/--help
USAGE
end
case @search.first
when '-i', '--images'
search_images
when '-yt', '--youtube'
search_youtube
when '-so', '--stack'
search_stack
when '-wiki', '--wikipedia'
search_wiki
when '-wa', '--wolfram'
search_wolfram
when '-h', '--help', nil, '-'
usage
else
search_query
end