Skip to content

Commit 61fd82f

Browse files
committed
Adding ns-cli to the dotfiles.
This is mostly here just so I can track it. Oh, the memories.
1 parent afec694 commit 61fd82f

File tree

2 files changed

+311
-0
lines changed

2 files changed

+311
-0
lines changed

search/ns-cli.cgi

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#!/usr/bin/perl -w
2+
#
3+
# ns-cli.cgi -- replace Netscape's "smart search" with stuff we like.
4+
#
5+
# See the file README for instructions on how to use this. (If you don't
6+
# have the file, you can get it from <http://www.lafferty.ca/software/>.)
7+
#
8+
# Thanks to Stefan `Sec` Zehl for the pointer about that NS preference.
9+
#
10+
# SEND ME <[email protected]> YOUR USEFUL SEARCHES! :-)
11+
#
12+
# 2002/08/09 Rich <[email protected]>
13+
# - Fix mozilla instructions again
14+
# - Rewrite with conf file instead of inline configuration
15+
# - Add "help me"
16+
# - More example commands
17+
# 2002/05/16 Rich <[email protected]>
18+
# - Fix mozilla instructions
19+
# - More example commands
20+
# 2001/03/19 Rich <[email protected]>
21+
# - use regex that works!
22+
# 2001/03/19 Rich <[email protected]>
23+
# - expect 'keyword' or 'kwoff', not just 'kwoff', which means that
24+
# keywords are turned off.
25+
# 2001/03/19 Rich Lafferty <[email protected]>
26+
# - first clean version.
27+
28+
use strict;
29+
use CGI qw(:cgi);
30+
use URI::Escape;
31+
use vars qw(%search $allowed);
32+
33+
# We expect ns-cli.conf to be in the current working directory.
34+
# Chane the following line if it isn't.
35+
36+
my $conf = "./ns-cli.conf";
37+
38+
do $conf;
39+
40+
# Allowed hosts
41+
if (defined $allowed and $ENV{REMOTE_ADDR} !~ /$allowed/) {
42+
print header;
43+
print "<p>This host is not permitted to access this function.\n";
44+
exit;
45+
}
46+
47+
my $request = $ENV{QUERY_STRING};
48+
# Uses "keyword" if Internet Keywords is enabled, "kwoff" if they're not.
49+
# Interesting -- if you didn't use nscli, you'd still be sending your
50+
# mistyped URLs to Netscape.
51+
$request =~ s,^keyword/,,;
52+
53+
my $word_delimeter = qr/(?:\s+|\+|%20)/;
54+
my ($func, $words) = split($word_delimeter, $request, 2);
55+
my @words = map { uri_unescape($_) } split($word_delimeter, $words);
56+
57+
show_help() if $func eq 'help';
58+
59+
unless (exists $search{$func}) {
60+
unshift (@words, $func);
61+
$func = 'default';
62+
}
63+
64+
if (exists $search{$func}->{SYNONYM}) {
65+
$func = $search{$func}->{SYNONYM};
66+
}
67+
68+
die "Default action '$func' doesn't exist in \%search\n"
69+
unless exists ($search{$func});
70+
71+
my $query = uri_escape (join (" ", @words));
72+
die "No URL listed for $func in $conf\n" unless exists $search{$func}->{URL};
73+
$search{$func}->{URL} =~ s/%%QUERY%%/$query/g;
74+
print redirect($search{$func}->{URL});
75+
76+
sub show_help {
77+
print <<__HTML__;
78+
Content-Type:text/html
79+
80+
<H2><a href="http://www.lafferty.ca/software/">ns-cli</a>, the Netscape command-line interface</H2>
81+
82+
<H3>Available Commands</H3>
83+
<pre>
84+
__HTML__
85+
86+
for my $key (sort keys %search) {
87+
my $text = exists $search{$key}->{SYNONYM} ? "Synonym for <b>$search{$key}->{SYNONYM}</b>" :
88+
$search{$key}->{DESC};
89+
printf(" %12s %s\n", $key, $text);
90+
}
91+
92+
print <<__HTML__;
93+
<p><small>This is free software with ABSOLUTELY NO WARRANTY. This program is
94+
released under the same terms as Perl itself (specifically, under your
95+
choice of either the GNU Public License version 2, or the Perl
96+
Artistic License). Copyright (c) 2002 Rich Lafferty.</small></p>
97+
__HTML__
98+
99+
exit;
100+
}
101+
102+

search/ns-cli.conf

+209
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
#
2+
# ns-cli.conf -- configuration file for ns-cli.
3+
#
4+
# What am I talking about? See <http://www.lafferty.ca/software/>.
5+
#
6+
# How do I use this? See the README in the ns-cli package.
7+
8+
# Regex to match allowed addresses -- leave blank to allow access
9+
# from anywhere
10+
11+
$allowed = '';
12+
13+
# define your fave URLs here.
14+
#
15+
# Format:
16+
#
17+
# key => {URL => 'http://foo.com/search.cgi?term=%%QUERY%%',
18+
# DESC => 'Search foo.com'}
19+
#
20+
# (The query "key word1 word2" will redirect the user to
21+
# <http://foo.com/search.cgi?term=word1+word2>, and the 'help me'
22+
# query will show "key Search foo.com".)
23+
#
24+
# key => {SYNONYM => 'otherkey'}
25+
#
26+
# (Entering "key" will do the same thing as entering "otherkey",
27+
# which must be defined as well. Synonyms cannot point to other
28+
# synonyms.)
29+
30+
%search = (
31+
32+
# If the first word doesn't match any command, we do this. This lets
33+
# you type "cold beans" instead of "find cold beans", for instance.
34+
default => {SYNONYM => 'google'},
35+
36+
# Google
37+
google => {URL => 'http://www.google.com/search?query=%%QUERY%%',
38+
DESC => 'Search the web with Google'},
39+
find => {SYNONYM => 'google'},
40+
lucky => {SYNONYM => 'go'},
41+
go => {URL => 'http://www.google.com/search?btnI=I%27m+Feeling+Lucky&query=%%QUERY%%',
42+
DESC => 'Go to first result of Google search ("I feel lucky")'},
43+
googleimg => {URL => 'http://images.google.com/images?q=%%QUERY%%',
44+
DESC => 'Search the web for images with Google'},
45+
img => {SYNONYM => 'googleimg'},
46+
usenet => {URL => 'http://groups.google.com/groups?num=100&q=QUERY',
47+
DESC => 'Search Usenet with Google'},
48+
googlemaps => {URL => 'http://maps.google.com/?q=%%QUERY%%',
49+
DESC => 'Search with Google Maps'},
50+
map => {SYNONYM => 'googlemaps'},
51+
52+
53+
# Dictionaries, thesauruses
54+
oed => {URL => 'http://dictionary.oed.com/cgi/findword?query_type=word&find=find&queryword=%%QUERY%%',
55+
DESC => 'Look up word in online Oxford English Dictionary'},
56+
mw => {URL => 'http://www.m-w.com/cgi-bin/dictionary?book=Dictionary&va=%%QUERY%%',
57+
DESC => 'Look up word in Merriam-Webster Collegiate Dictionary'},
58+
thesaurus => {URL => 'http://thesaurus.reference.com/browse/%%QUERY%%',
59+
DESC => "Look up word in Roget's New Thesaurus"},
60+
thes => {SYNONYM => 'thesaurus'},
61+
foldoc => {URL => 'http://wombat.doc.ic.ac.uk/foldoc/foldoc.cgi?query=%%QUERY%%',
62+
DESC => "Look up word in the Free On-line Dictionary of Computing"},
63+
dictionary => {URL => 'http://dictionary.reference.com/browse/%%QUERY%%',
64+
DESC => "Look up word in Random House Dictionary"},
65+
dict => {SYNONYM => 'dictionary'},
66+
67+
# Software repositories, etc
68+
cpan => {URL => 'http://search.cpan.org/search?mode=module&query=%%QUERY%%',
69+
DESC => 'Search for Perl module on CPAN'},
70+
rpm => {URL => 'http://www.rpmfind.net/linux/rpm2html/search.php?query=%%QUERY%%',
71+
DESC => 'Search for RPMs on rpmfind.net'},
72+
rpmfind => {SYNONYM => 'rpm'},
73+
fm => {URL => 'http://freshmeat.net/search/?section=projects&q=%%QUERY%%',
74+
DESC => 'Search for project on Freshmeat'},
75+
fmp => {URL => 'http://freshmeat.net/projects/%%QUERY%%/',
76+
DESC => 'Go to Freshmeat project by name'},
77+
sf => {URL => 'http://sourceforge.net/projects/%%QUERY%%/',
78+
DESC => 'Go to SourceForge project by name'},
79+
phpman => {URL => 'http://www.php.net/%%QUERY%%',
80+
DESC => 'Search PHP manual'},
81+
rfc => {URL => 'http://www.faqs.org/rfcs/rfc%%QUERY%%.html',
82+
DESC => 'Bring up hypertext RFC by number'},
83+
bug => {URL => 'http://your-bugzilla-url/show_bug.cgi?id=%%QUERY%%',
84+
DESC => 'Customize this to bring up Bugzilla bugs by number'},
85+
rt => {URL => 'http://your-rt-url/Ticket/Display.html?id=%%QUERY%%',
86+
DESC => 'Customize this to bring up RT tickets by number'},
87+
linuxt => {URL => 'http://linuxtoday.com/search.php3?query=%%QUERY%%',
88+
DESC => 'Search LinuxToday'},
89+
90+
# Communities
91+
livej => {URL => 'http://www.livejournal.com/~%%QUERY%%/',
92+
DESC => 'Go to LiveJournal for indicated user'},
93+
lj => {SYNONYM => 'livej'},
94+
liveji => {URL => 'http://www.livejournal.com/userinfo.bml?user=%%QUERY%%',
95+
DESC => 'Go to LiveJournal userinfo page for user'},
96+
lji => {SYNONYM => 'liveji'},
97+
ljint => {URL => 'http://www.livejournal.com/interests.bml?int=%%QUERY%%',
98+
DESC => 'See results for LiveJournal interest'},
99+
advo => {URL => 'http://www.advogato.org/person/%%QUERY%%/',
100+
DESC => 'Go to Advogato page for indicated user'},
101+
102+
# Other stuff
103+
validate => {URL => 'http://validator.w3.org/check?uri=%%QUERY%%',
104+
DESC => 'Validate HTML at indicated URL'},
105+
bobby => {URL => 'http://bobby.cast.org/bobby?URL=%%QUERY%%&output=Submit',
106+
DESC => 'Test HTML at indicated URL for accessibility'},
107+
ebay => {URL => 'http://search.ebay.com/search/search.dll?MfcISAPICommand=GetResult&ht=1&SortProperty=MetaEndSort&query=%%QUERY%%',
108+
DESC => 'Search eBay'},
109+
ebayn => {URL => 'http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&item=%%QUERY%%',
110+
DESC => 'Go to eBay auction by number'},
111+
quote => {URL => 'http://finance.yahoo.com/q?s=%%QUERY%%&d=c',
112+
DESC => 'Stock quote and chart from Yahoo Finance'},
113+
stock => {SYNONYM => 'quote'},
114+
symbol => {URL => 'http://finance.yahoo.com/l?m=US&s=%%QUERY%%',
115+
DESC => 'Look up a stock symbol'},
116+
shorten => {URL => 'http://makeashorterlink.com/index.php?url=%%QUERY%%',
117+
DESC => 'Create makeashorterlink.com link to URL'},
118+
olga => {URL => 'http://rhythm.harmony-central.com/olga-query.php?key=%%QUERY%%&Search=Song/',
119+
DESC => 'Search On-line Guitar Archive for tablature'},
120+
imdb => {URL => 'http://www.imdb.com/find?s=all&q=%%QUERY%%',
121+
DESC => 'Search Internet Movie Database'},
122+
bashorg => {URL => 'http://www.bash.org/?%%QUERY%%',
123+
DESC => 'Search bash.org (IRC Quotes)'},
124+
bash => {SYNONYM => 'bashorg'},
125+
jerkcity => {URL => 'http://www.jerkcity.com/search/index.cgi?q=%%QUERY%%',
126+
DESC => 'Search Jerkcity strips'},
127+
jerk => {SYNONYM => 'jerkcity'},
128+
pennyarcade => {URL => 'http://www.penny-arcade.com/search.php?keywords=%%QUERY%%&jointype=1&searchtype=2',
129+
DESC => 'Search Penny Arcade strips'},
130+
pa => {SYNONYM => 'pennyarcade'},
131+
urbandict => {URL => 'http://www.urbandictionary.com/define.php?term=%%QUERY%%',
132+
DESC => 'Search for word/phrase in Urban Dictionary'},
133+
ud => {SYNONYM => 'urbandict'},
134+
urban => {SYNONYM => 'urbandict'},
135+
udict => {SYNONYM => 'urbandict'},
136+
wikipedia => {URL => 'http://en.wikipedia.org/w/wiki.phtml?search=%%QUERY%%&go=GO',
137+
DESC => 'Go to word/phrase in Wikipedia'},
138+
wiki => {SYNONYM => 'wikipedia'},
139+
w => {SYNONYM => 'wikipedia'},
140+
everything2 => {URL => 'http://everything2.com/index.pl?node=%%QUERY%%',
141+
DESC => 'Go to word/phrase in Everything2'},
142+
e2 => {SYNONYM => 'everything2'},
143+
amg_artist => { URL => 'http://www.allmusic.com/cg/amg.dll?p=amg&opt1=1&sql=%%QUERY%%',
144+
DESC => 'Search All Music Guide by Artist'},
145+
amg_album => { URL => 'http://www.allmusic.com/cg/amg.dll?p=amg&opt1=2&sql=%%QUERY%%',
146+
DESC => 'Search All Music Guide by Album'},
147+
amg_song => { URL => 'http://www.allmusic.com/cg/amg.dll?p=amg&opt1=3&sql=%%QUERY%%',
148+
DESC => 'Search All Music Guide by Song'},
149+
amg => {SYNONYM => 'amg_artist'},
150+
acronym_exact => { URL => 'http://www.acronymfinder.com/af-query.asp?p=dict&String=exact&Acronym=%%QUERY%%',
151+
DESC => 'Search Acronym Finder (exact)'},
152+
acronym => {SYNONYM => 'acronym_exact'},
153+
answers => { URL => 'http://www.answers.com/%%QUERY%%',
154+
DESC => 'Search Answers.com',
155+
},
156+
answer => {SYNONYM => 'answers'},
157+
ans => {SYNONYM => 'answers'},
158+
snopes => { URL => 'http://search.atomz.com/search/?sp-q=%%QUERY%%&sp-a=00062d45-sp00000000&sp-advanced=1&sp-p=all&sp-w-control=1&sp-w=alike&sp-date-range=-1&sp-x=any&sp-c=100&sp-m=1&sp-s=0',
159+
DESC => 'Search Snopes Urban Legends Reference Pages',
160+
},
161+
toothpastefordinner => { URL => 'http://www.toothpastefordinner.com/search.php?search=%%QUERY%%',
162+
DESC => 'Search toothpaste for dinner strips',
163+
},
164+
toothpaste => {SYNONYM => 'toothpastefordinner'},
165+
yahooweather => { URL => 'http://weather.yahoo.com/search/weather2?p=%%QUERY%%',
166+
DESC => 'Get weather information from Yahoo!',
167+
},
168+
'4cast' => { URL => 'http://4ca.st/?getlocation=%%QUERY%%',
169+
DESC => 'Get weather information from 4cast',
170+
},
171+
weather => {SYNONYM => '4cast'},
172+
etymology => { URL => 'http://www.etymonline.com/index.php?search=%%QUERY%%',
173+
DESC => 'Search online etymology dictionary',
174+
},
175+
etym => { SYNONYM => 'etymology' },
176+
powerset => { URL => 'http://www.powerset.com/explore/pset?q=%%QUERY%%',
177+
DESC => 'Search Powerset',
178+
},
179+
pset => { SYNONYM => 'powerset' },
180+
181+
phonespell => { URL => 'http://www.phonespell.org/combo.cgi?n=%%QUERY%%',
182+
DESC => 'What does your phone number spell?',
183+
},
184+
phone => { SYNONYM => 'phonespell' },
185+
gamefaq => { URL => 'http://www.gamefaqs.com/search/index.html?game=%%QUERY%%&platform=0&s=s',
186+
DESC => 'GameFAQs search',
187+
},
188+
gf => { SYNONYM => 'gamefaq' },
189+
termly => { URL => 'http://term.ly/%%QUERY%%',
190+
DESC => 'Search term.ly',
191+
},
192+
term => { SYNONYM => 'termly' },
193+
scrabblecheck => { URL => 'http://scrabbletools.appspot.com/search?word=%%QUERY%%',
194+
DESC => 'Check validity of Scrabble word',
195+
},
196+
scrabble => { SYNONYM => 'scrabblecheck' },
197+
emusicall => { URL => 'http://www.emusic.com/listen/#/search.html?mode=x&QT=%%QUERY%%&=:',
198+
DESC => 'Check emusic.com (all)',
199+
},
200+
emusic => { SYNONYM => 'emusicall' },
201+
tvtropes => { URL => 'http://www.google.com/search?query=site:tvtropes.org%20%%QUERY%%',
202+
DESC => 'Search TV Tropes' },
203+
trope => { SYNONYM => 'tvtropes' },
204+
);
205+
206+
207+
# Leave this here!
208+
1;
209+

0 commit comments

Comments
 (0)