You are not logged in.
Pages: 1
I love Surfraw and I can't fathom why the ten-year old project doesn't have an elvis for searching the best GNU/Linux wiki on the web. So I have had a crack at it.
The code is ugly, and there is probably quite a lot that could be done to make it more elegant and efficient - if you have suggestions, please post them.
I have done (minimal) testing and it seems to work as intended across the various different language wikis, but again, there could probably be improvements.
#!/bin/sh
# elvis: archwiki -- Search the Arch Linux Wiki
# Author: http://jasonwryan.com
. surfraw || exit 1
w3_config_hook () {
def SURFRAW_archwiki_language "$SURFRAW_lang"
}
w3_usage_hook () {
cat <<EOF
Usage: $w3_argv0 [options] [search-string]
Description:
Search the Arch Linux Wiki (wiki.archlinux.org)
Local options
-language=ISOCODE | -l=ISOCODE Two letter language code (resembles ISO country codes)
en | Main Arch Wiki site (default)
fr | French
de | German
he | Hebrew
pl | Polish
pt | Portugese
ro | Romanian
es | Spanish
sv | Swedish
uk | Ukranian
Environment: SURFRAW_archwiki_language, SURFRAW_lang
Default: en
EOF
w3_global_usage
}
w3_parse_option_hook () {
opt="$1"
optarg="$2"
case "$opt" in
-language=*) setopt SURFRAW_archwiki_language $optarg ;;
-l=*) setopt SURFRAW_archwiki_language $optarg ;;
*) return 1 ;;
esac
return 0
}
w3_config
w3_parse_args "$@"
# w3_args now contains list of arguments
case "$SURFRAW_archwiki_language" in
en) domain=".org" ;;
fr) domain=".fr" ;;
de) domain=".de" ;;
he) domain=".il" ;;
pl) domain=".pl" ;;
pt) domain="-br.org" ;;
ro) domain=".ro" ;;
es) domain=".cl" ;;
sv) domain=".sv" ;;
uk) domain=".ua" ;;
*) domain=".org" ;;
esac
# handle ssl
if [ $domain = ".org" -o $domain = ".de" ]; then
protocol="https://";
else
protocol="http://";
fi
if [ -z "$w3_args" ]; then
w3_browse_url "${protocol}wiki.archlinux${domain}/"
else
escaped_args=$(w3_url_of_arg $w3_args)
w3_browse_url "${protocol}wiki.archlinux${domain}/index.php?search=${escaped_args}"
fi
# edit: improved ssl if statement
# edit 2: changed thread title to reflect other elvi
Last edited by jasonwryan (2011-04-12 23:36:29)
Offline
nice work! will give it a go later.
Offline
I have written a couple of others.
One for Stack Overflow, with a switch for Unix & Linux Stack Exchange
#!/bin/sh
# elvis: stack -- Search Stack Overflow
# Author: jason ryan • http://jasonwryan.com
. surfraw || exit 1
w3_config_hook () {
def SURFRAW_stack_categories "$SURFRAW_categories"
def SURFRAW_stack_unix 0
def SURFRAW_stack_results 25
}
w3_usage_hook () {
cat <<EOF
Usage: $w3_argv0 [options] [search-string]
Description:
Search Stack Overflow (http://stackoverflow.com)
Combine search terms (tags) with a "+" eg., "bash+script"
Local options:
-sort=CATEGORIES | -s=CATEGORIES
new | Most recently asked (default)
feat | Questions with open bounties
vote | Questions with most votes
active | Recently active
null | No upvoted answers
faq | Questions with the most links
Default: new
-u | Search Unix & Linux Exchange
Default: no
-num=NUMBER | Number of results per page
Default: $SURFRAW_stack_results
EOF
w3_global_usage
}
w3_parse_option_hook () {
opt="$1"
optarg="$2"
case "$opt" in
-sort=*) setopt SURFRAW_stack_categories $optarg ;;
-s=*) setopt SURFRAW_stack_categories $optarg ;;
-num=*) setopt SURFRAW_stack_results $optarg ;;
-u) setoptyn SURFRAW_stack_unix 1 ;;
*) return 1 ;;
esac
return 0
}
w3_config
w3_parse_args "$@"
# w3_args now contains list of arguments
case "$SURFRAW_stack_categories" in
new) category="newest" ;;
feat) category="featured" ;;
vote) category="votes" ;;
active) category="active" ;;
null) category="unanswered" ;;
faq) category="faq" ;;
*) category="newest" ;;
esac
# Check for Unix & Linux Exchange
if [ "$SURFRAW_stack_unix" = 1 ]; then
url="http://unix.stackexchange.com"
else
url="http://stackoverflow.com"
fi
# No arguments passed
if [ -z "$w3_args" ]; then
w3_browse_url "$url"
else
escaped_args=$(w3_url_of_arg $w3_args)
if [ -n "$SURFRAW_stack_categories" ]; then
w3_browse_url "${url}/questions/tagged/${escaped_args}?sort=${category}&pagesize=${SURFRAW_stack_results}"
else
w3_browse_url "${url}/questions/tagged/${escaped_args}"
fi
fi
and another for Delicious bookmarks
#!/bin/sh
# elvis: deli -- Search Delicious bookmarks
# Author: jason ryan • http://jasonwryan.com
. surfraw || exit 1
w3_config_hook () {
def SURFRAW_delicious_results $SURFRAW_results
def SURFRAW_delicious_tags $SURFRAW_tags
def SURFRAW_delicious_user $SURFRAW_user
}
w3_usage_hook () {
cat <<EOF
Usage: $w3_argv0 [options] [search-string]
Description:
Search Delicious bookmarks (www.delicious.com)
Local options
-tags=TAG | -t=TAG Refine your search with tags
[Separate multiple tags with "+"]
-user=USER | -u=USER Search a particular user's bookmarks
EOF
w3_global_usage
}
w3_parse_option_hook () {
opt="$1"
optarg="$2"
case "$opt" in
-tags=*) setopt SURFRAW_delicious_tags $optarg ;;
-t=*) setopt SURFRAW_delicious_tags $optarg ;;
-u=*) setopt SURFRAW_delicious_user $optarg ;;
-user=*) setopt SURFRAW_delicious_user $optarg ;;
*) return 1 ;;
esac
return 0
}
w3_config
w3_parse_args "$@"
# w3_args now contains list of arguments
# standard topic seach
if [ -z "$w3_args" ]; then
w3_browse_url "http://www.delicious.com/search?p=${SURFRAW_delicious_results}&chk=&context=all&fr=del_icio_us&lc=1"
else
escaped_args=$(w3_url_of_arg $w3_args)
# search for topic and tag(s) in a user's bookmarks
if [ -n "${SURFRAW_delicious_user}" -a "${SURFRAW_delicious_tags}" ]; then
w3_browse_url "http://www.delicious.com/search?p=${escaped_args}&chk=&fr=del_icio_us&lc=1&atags=${SURFRAW_delicious_tags}&rtags=&context=userposts%7C${SURFRAW_delicious_user}%7C"
# search for topic in a user's bookmarks
elif [ -n "${SURFRAW_delicious_user}" ]; then
w3_browse_url "http://www.delicious.com/search?p=${escaped_args}&chk=&context=userposts%7C${SURFRAW_delicious_user}&fr=del_icio_us&lc=1"
# search for topic with tag(s)
else
w3_browse_url "http://www.delicious.com/search?p=${escaped_args}&chk=&fr=del_icio_us&lc=1&atags=${SURFRAW_delicious_tags}&rtags=&context=userposts=all"
fi
fi
Offline
Very nice. I had made awhile ago modified an existing elvi to give me basic support for the archwiki, but yours is very sophisticated and well done. Thanks.
Could you possibly make the search of the archwiki case insensitive? It automatically capitalizes the first word, but if I use two words, the second is not capitalized (so I'm not automatically taken to the right entry, for instance if I run "archwiki tablet pc").
Also, there appears to be an extra fi on the last line of the archwiki elvi.
Last edited by Sara (2011-04-23 07:01:40)
Registed Linux User 483618
Offline
Very nice. I had made awhile ago modified an existing elvi to give me basic support for the archwiki, but yours is very sophisticated and well done. Thanks.
You're welcome.
Could you possibly make the search of the archwiki case insensitive? It automatically capitalizes the first word, but if I use two words, the second is not capitalized (so I'm not automatically taken to the right entry, for instance if I run "archwiki tablet pc").
I have had a quick look and it seems that the issue is with MediaWiki [http://meta.wikimedia.org/wiki/Case_sen … page_names]. Without a case-sensitivity argument for the search term, I'm not sure how to make it work in Surfraw. But I'll see what else I can find...
Also, there appears to be an extra fi on the last line of the archwiki elvi.
Thanks - fixed!
Offline
I have tweaked the Arch Package elvi to include some more options.
#!/bin/sh
# elvis: archpkg -- Search Arch Linux Packages (www.archlinux.org/packages/)
# Author: jason ryan • http://jasonwryan.com
. surfraw || exit 1
w3_config_hook () {
def SURFRAW_arch_ix "$SURFRAW_ix"
def SURFRAW_arch_repo "$SURFRAW_repo"
def SURFRAW_arch_date "$SURFRAW_date"
def SURFRAW_arch_results 25
}
w3_usage_hook () {
cat <<EOF
Usage: $w3_argv0 [options] [search string]
Description: Surfraw search Arch Linux packages (www.archlinux.org)
Local options:
-arch=ARCHITECTURES | -a=ARCHITECTURES
any | Any (default)
i686 | i686
x86_64 | x86_64
-repo=REPOSITORIES | -r=REPOSITORIES
comm | Community
commtest | Community-Testing
core | Core
extra | Extra
multi | Multilib
multitest | Multilib-Testing
test | Testing
Default: All
-date=UPDATED | -d=UPDATED (format: YYYY-MM-DD)
-num=NUMBER | Number of results per page
Default: $SURFRAW_arch_results
EOF
w3_global_usage
}
w3_parse_option_hook () {
opt="$1"
optarg="$2"
case "$opt" in
-a*=*) setopt SURFRAW_arch_ix $optarg ;;
-r*=*) setopt SURFRAW_arch_repo $optarg ;;
-d*=*) setopt SURFRAW_arch_date $optarg ;;
-n*=*) setopt SURFRAW_arch_results $optarg ;;
*) return 1 ;;
esac
return 0
}
w3_config
w3_parse_args "$@"
# selected repository
case "$SURFRAW_arch_repo" in
comm) repo="Community" ;;
commtest) repo="Community-Testing" ;;
core) repo="Core" ;;
extra) repo="Extra" ;;
multi) repo="Multilib" ;;
multitest)repo="Multilib-Testing" ;;
test) repo="Testing" ;;
*) repo="" ;;
esac
# no arguments present
if [ -z "$w3_args" ]; then
w3_browse_url "http://www.archlinux.org/packages/"
else
# if w3_args contains a list of arguments
escaped_args=$(w3_url_of_arg $w3_args)
base="http://www.archlinux.org/packages/?sort="
# repository and architecture
if [ -n "$SURFRAW_arch_repo" -a "$SURFRAW_arch_ix" ]; then
w3_browse_url "${base}&arch=${SURFRAW_arch_ix}&repo=${repo}&q=${escaped_args}&maintainer=&last_update=${SURFRAW_arch_date}&flagged=&limit=${SURFRAW_arch_results}"
# check for repository
elif [ -n "$SURFRAW_arch_repo" ]; then
w3_browse_url "${base}&repo=${repo}&q=${escaped_args}&maintainer=&last_update=${SURFRAW_arch_date}&flagged=&limit=${SURFRAW_arch_results}"
# just architecture
elif [ -n "$SURFRAW_arch_ix" ]; then
w3_browse_url "${base}&arch=${SURFRAW_arch_ix}&q=${escaped_args}&maintainer=&last_update=${SURFRAW_arch_date}&flagged=&limit=${SURFRAW_arch_results}"
# none of the above...
else
w3_browse_url "${base}&q=${escaped_args}&maintainer=&last_update=${SURFRAW_arch_date}&flagged=&limit=${SURFRAW_arch_results}"
fi
fi
Offline
One for github.
It doesn't work in w3m (I have filed a bug report), so I have only tested it in Lynx. If there are any issues with it, please let me know.
#!/bin/sh
# elvis: github -- Search Github (https://github.com)
# Author: jason ryan • https://jasonwryan.com
. surfraw || exit 1
w3_config_hook () {
def SURFRAW_git_type "$SURFRAW_type"
def SURFRAW_git_lang any
}
w3_usage_hook () {
cat <<EOF
Usage: $w3_argv0 [options] [search-string]
Description:
Search Github (https://github.com)
Local options:
-l=LANGUAGE | -lang=LANGUAGE
Languages are case sensitive, eg., C, Shell, Python etc.
Languages with spaces must be conjoined with a "+", eg, Common+Lisp
Default: Any
-type=SEARCH | -t=SEARCH
every | Everything
repo | Repositories
user | Users
code | Code
Default: Everything
EOF
w3_global_usage
}
w3_parse_option_hook () {
opt="$1"
optarg="$2"
case "$opt" in
-t*=*) setopt SURFRAW_git_type $optarg ;;
-l*=*) setopt SURFRAW_git_lang $optarg ;;
*) return 1 ;;
esac
return 0
}
w3_config
w3_parse_args "$@"
# w3_args now contains list of arguments
# type of search selected
case "$SURFRAW_git_type" in
every) type="Everything" ;;
repo) type="Repositories" ;;
user) type="Users" ;;
code) type="Code" ;;
*) type="Everything" ;;
esac
# No arguments parsed
if [ -z "$w3_args" ]; then
w3_browse_url "https://github.com"
else
# Language and/or search type selected
escaped_args=$(w3_url_of_arg $w3_args)
w3_browse_url "https://github.com/search?type=${type}&language=${SURFRAW_git_lang}&q=${escaped_args}&repo=&langOverride=&x=0&y=0&start_value=1"
fi
Offline
...and for those of you, like me that have been astounded by the inept redesign of delicious, here is an elvis for pinboard.
#!/bin/sh
# elvis: pin -- Search Pinboard bookmarks (http://pinboard.in)
# author: jason ryan • http://jasonwryan.com
. surfraw || exit 1
w3_config_hook () {
def SURFRAW_pinboard_tags "$SURFRAW_tags"
def SURFRAW_pinboard_user "$SURFRAW_user"
def SURFRAW_pinboard_new 0
def SURFRAW_pinboard_popular 0
}
w3_usage_hook () {
cat <<EOF
Usage: $w3_argv0 [options] [search words]...
Description:
Surfraw search Pinboard bookmarks (http://pinboard.in)
Local options:
-popular | -p Search popular tags
-recent | -r Search recent tags
-tags=TAGS | -t=TAGS Search tags (separate TAGS with "+" eg., unix+linux)
-user=NAME | -u=NAME Search a user's bookmarks
Default: tags
EOF
w3_global_usage
}
w3_parse_option_hook () {
opt="$1"
optarg="$2"
case "$opt" in
-p* ) setoptyn SURFRAW_pinboard_popular 1 ;;
-r* ) setoptyn SURFRAW_pinboard_new 1 ;;
-t=*) setopt SURFRAW_pinboard_tags $optarg ;;
-u=*) setopt SURFRAW_pinboard_user $optarg ;;
*) return 1 ;;
esac
return 0
}
# create tag string
tags () {
local IFS="+"
for tag in $SURFRAW_pinboard_tags; do
printf "%s" "t:$tag/"
done
}
w3_config
w3_parse_args "$@"
# w3_args now contains a list of arguments
base_url="https://pinboard.in/"
# check for recent & popular
if [ "$SURFRAW_pinboard_new" = 1 ]; then
suffix="recent/"
elif [ "$SURFRAW_pinboard_popular" = 1 ]; then
suffix="popular"
fi
# Run through the other possibilities...
if [ -z "$w3_args" ]; then
if [ -n "$SURFRAW_pinboard_user" ] && [ -n "$SURFRAW_pinboard_tags" ]; then
w3_browse_url "${base_url}u:$SURFRAW_pinboard_user/$(tags)"
elif [ -n "$SURFRAW_pinboard_tags" ]; then
w3_browse_url "${base_url}$(tags)"
elif [ -n "$SURFRAW_pinboard_user" ]; then
w3_browse_url "${base_url}u:$SURFRAW_pinboard_user"
else w3_browse_url "$base_url${suffix}"
fi
elif [ -n "$w3_args" ]; then
escaped_args=$(w3_url_of_arg $w3_args)
w3_browse_url "${base_url}search/?query=${escaped_args}&all=Search+All"
else
w3_browse_url "${base_url}"
fi
As always, any comments about ways to improve the code (particularly the logic) welcome...
Offline
I just recently discovered Surfraw and so far I love it. I wanted to try my hand at writing an elvis and since I am currently doing a lot of programming in PHP I decided to create one for php.net. From the site you can search various things including the functions, bugs, mailing lists, etc... so I included a flag for each one. Anyway, just thought I would share.
#!/bin/sh
# elvis: php -- Search PHP.net
# Author: http://jonyamo.net
. surfraw || exit 1
w3_config_hook () {
def SURFRAW_php_language "$SURFRAW_lang"
def SURFRAW_php_search "functions"
}
w3_usage_hook () {
cat <<EOF
Usage: $w3_argv0 [options] [search-string]
Description:
Search PHP.net
Local options:
-l, -language= Two letter language code (resembles ISO country codes)
en | English (default)
pt | Brazilian Portuguese
zh | Chinese (Simplified)
fr | French
de | German
ja | Japanese
pl | Polish
ro | Romanian
fa | Persian
es | Spanish
tr | Turkish
Environment: SURFRAW_php_language, SURFRAW_lang
Default: en
-s, -search= Specialized search on topic
all | All php.net sites
functions | Function search
manual | Online documentation
bugs | Bug database
news | News archive
changelogs | Changelogs
pear | Just pear.php.net
pecl | Just pecl.php.net
talks | Just talks.php.net
maillist | General mailing list
devlist | Developer mailing list
phpdoc | Documentation mailing list
Environment: SURFRAW_php_search
Default: functions
-a, -all alias of -search=all
-f, -functions alias of -search=functions
-m, -manual alias of -search=manual
-b, -bugs alias of -search=bugs
-n, -news alias of -search=news
-c, -changelogs alias of -search=changelogs
-t, -talks alias of -search=talks
-maillist alias of -search=maillist
-devlist alias of -search=devlist
-phpdoc alias of -search=phpdoc
EOF
w3_global_usage
}
w3_parse_option_hook () {
opt="$1"
optarg="$2"
case "$opt" in
-language=*) setopt SURFRAW_php_language "$optarg" ;;
-l=*) setopt SURFRAW_php_language "$optarg" ;;
-search=*) setopt SURFRAW_php_search "$optarg" ;;
-s=*) setopt SURFRAW_php_search "$optarg" ;;
-a|-all) setopt SURFRAW_php_search "all" ;;
-f|-functions) setopt SURFRAW_php_search "functions" ;;
-m|-manual) setopt SURFRAW_php_search "manual" ;;
-b|-bugs) setopt SURFRAW_php_search "bugs" ;;
-n|-news) setopt SURFRAW_php_search "news" ;;
-c|-changelogs) setopt SURFRAW_php_search "changelogs" ;;
-t|-talks) setopt SURFRAW_php_search "talks" ;;
-maillist) setopt SURFRAW_php_search "maillist" ;;
-devlist) setopt SURFRAW_php_search "devlist" ;;
-phpdoc) setopt SURFRAW_php_search "phpdoc" ;;
*) return 1 ;;
esac
return 0
}
w3_config
w3_parse_args "$@"
# w3_args now contains a list of arguments
url="http://php.net/"
case "$SURFRAW_php_language" in
en) lang="en" ;;
pt) lang="pt_BR" ;;
zh) lang="zh" ;;
fr) lang="fr" ;;
de) lang="de" ;;
ja) lang="ja" ;;
pl) lang="pl" ;;
ro) lang="ro" ;;
fa) lang="fa" ;;
es) lang="es" ;;
tr) lang="tr" ;;
*) lang="en" ;;
esac
case "$SURFRAW_php_search" in
all) search="all" ;;
functions) search="quickref" ;;
manual) search="manual" ;;
bugs) search="bugdb" ;;
news) search="news_archive" ;;
changelogs) search="changelogs" ;;
pear) search="pear" ;;
pecl) search="pecl" ;;
talks) search="talks" ;;
maillist) search="maillist" ;;
devlist) search="devlist" ;;
phpdoc) search="phpdoc" ;;
*) search="functions" ;;
esac
if [ -n "$w3_args" ]; then
escaped_args=$(w3_url_of_arg $w3_args)
url="${url}search.php?lang=${lang}&show=${search}&pattern=${escaped_args}"
fi
w3_browse_url "$url"
Last edited by jonyamo (2011-10-05 20:53:19)
Offline
NIce work! Send it to the ML for inclusion in the next release...
Offline
Pages: 1