Skip to content

Instantly share code, notes, and snippets.

@lee2sman
Last active September 18, 2016 06:34
Show Gist options
  • Save lee2sman/e3a77288a03d937ea92be1fb9c5c56be to your computer and use it in GitHub Desktop.
Save lee2sman/e3a77288a03d937ea92be1fb9c5c56be to your computer and use it in GitHub Desktop.
Commandline Wikipedia Search - put this in your $PATH like usr/local/bin - it's a brute force hack but it works
#!/bin/bash
#
# wikisearch: Wikipedia search in the commandline
# cc0 by Lee2sman 2016
# DEPENDENCIES: w3m
# USAGE: wikisearch [search term]
hash w3m &> /dev/null
if [ $? -eq 1 ] #Checks to see if w3m is installed
then
echo >&2 "w3m must be installed to use wikisearch."
exit 1
elif [ $# -eq 0 ]
then
#Exits if haven't entered anything to search after wikisearch
echo "No search arguments entered."
echo "USAGE: wikisearch [search term]"
exit 1
else
# Escape spaces for URL
a="$*"
q=${a// /+}
w3m -dump "https://en.wikipedia.org/w/index.php?title=Special:Search&search=$q&go=Go" | more
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment