w3m alias search engine

pull/45/head
gotbletu 3 years ago
parent dced2891c0
commit 85fc35ccbe

@ -0,0 +1,88 @@
#!/usr/bin/env sh
# AUTHOR: gotbletu (@gmail|twitter|youtube|github|lbry|odysee)
# https://www.youtube.com/user/gotbletu
# DESC: w3m search engine alias (aka smart keywords search)
# DEMO: https://youtu.be/bWlPpacFPlI
# W3M Playlist https://www.youtube.com/playlist?list=PLqv94xWU9zZ35Yv0s6zMID5JoS8qu19Kh
# REFF: https://github.com/felipesaa/A-vim-like-firefox-like-configuration-for-w3m/blob/master/cgi-bin/search_engines.cgi
# https://github.com/felipesaa/A-vim-like-firefox-like-configuration-for-w3m/blob/master/documentation/search_engines.txt
# https://github.com/felipesaa/A-vim-like-firefox-like-configuration-for-w3m/blob/master/urimethodmap
# frakswe search surfraw urimethodmap https://pastebin.com/raw/TUcRgu9y
# https://rubikitch.hatenadiary.org/entry/20070830/searchengine
# REQD: 1. touch ~/.w3m/urimethodmap
# 2. $EDITOR ~/.w3m/urimethodmap
# # search engine alias
# # note: no trailing space after %s
# 1x: file:/cgi-bin/search_engines.cgi?%s
# dd: file:/cgi-bin/search_engines.cgi?%s
# gg: file:/cgi-bin/search_engines.cgi?%s
# gs: file:/cgi-bin/search_engines.cgi?%s
# pb: file:/cgi-bin/search_engines.cgi?%s
# rd: file:/cgi-bin/search_engines.cgi?%s
# wi: file:/cgi-bin/search_engines.cgi?%s
# v2: file:/cgi-bin/search_engines.cgi?%s
# ya: file:/cgi-bin/search_engines.cgi?%s
# yt: file:/cgi-bin/search_engines.cgi?%s
# 3. chmod +x ~/.w3m/cgi-bin/search_engines.cgi
# 4. sed -i 's@cgi_bin.*@cgi_bin ~/.w3m/cgi-bin:/usr/lib/w3m/cgi-bin:/usr/local/libexec/w3m/cgi-bin@g' ~/.w3m/config
# 5. sed -i 's@urimethodmap.*@urimethodmap ~/.w3m/urimethodmap, /usr/etc/w3m/urimethodmap@g' ~/.w3m/config
# USAGE: <SearchEngine>:<Keywords;Use;SemiColon;As;Spaces>
# 1. $ w3m -v
# 2. press Shift-u (the default GOTO key) to access the addressbar
# 3. press Ctrl-u to clear addressbar
# 4. to search duckduckgo type in dd:linux;wallpapers
# 5. to search google type in gg:anime;wallpapers
# CLOG: 2021-05-24 turn @felipesaa script into posix, use case statement looks prettier
# search engine alias
# dd:linux;wallpapers --> dd
PREFIX=$(echo "$QUERY_STRING" | cut -d ':' -f1)
# user input keywords
# dd:linux;wallpapers --> linux;wallpapers --> linux%20wallpapers
# [Note] w3m does not allow spaces in addressbar so using ';' as 'space' instead
INPUT=$(echo "$QUERY_STRING" | cut -d ':' -f2- | sed 's/;/%20/g')
# check if w3m version has native gopher support
GOPHER_PROTOCOL_ENABLE=$(w3m -version | grep -c "gopher")
case $PREFIX in
1x)
echo "W3m-control: GOTO https://1337x.to/search/$INPUT/1/"
;;
dd)
echo "W3m-control: GOTO https://lite.duckduckgo.com/lite/?q=$INPUT&kf=-1&kz=-1&kq=-1&kv=-1&k1=-1&kp=-2&kaf=1&kd=-1&kf=-1&kz=-1&kq=-1&kv=-1"
;;
gg)
echo "W3m-control: GOTO https://www.google.com/search?q=$INPUT"
;;
gs)
echo "W3m-control: GOTO https://portal.mozz.us/gemini/geminispace.info/search%3F$INPUT"
;;
pb)
echo "W3m-control: GOTO https://thepiratebay10.org/search/$INPUT"
;;
rd) # goto a subreddit by name
echo "W3m-control: GOTO https://www.reddit.com/r/$INPUT/.mobile"
;;
wi)
echo "W3m-control: GOTO https://en.wikipedia.org/w/index.php?search=$INPUT&title=Special%3ASearch&profile=default&fulltext=1&ns0=1"
;;
v2) # veronica-2 search gopherspace (use web proxy if no native support)
if [ "$GOPHER_PROTOCOL_ENABLE" = 0 ] ; then
echo "W3m-control: GOTO https://gopher.floodgap.com/gopher/gw?ss=gopher%3A%2F%2Fgopher.floodgap.com%2F7%2Fv2%2Fvs&sq=$INPUT"
else
echo "W3m-control: GOTO gopher://gopher.floodgap.com/7/v2/vs?$INPUT"
fi
;;
ya)
echo "W3m-control: GOTO https://search.yahoo.com/search?p=$INPUT"
;;
yt) # youtube via indivious
echo "W3m-control: GOTO https://yewtu.be/search?q=$INPUT"
;;
esac
# delete temp buffer
echo "W3m-control: DELETE_PREVBUF"
Loading…
Cancel
Save