Create shell aliases to quickly search reference sites from a terminal including DuckDuckGo, Wikipedia, Dictionary.com, AcronymFinder, Devhints, and FreshPorts.

I listened to episode #283 of The Changelog this week and learned about Devhints, which provides "cheatsheets" on a variety of development related topics. The hosts mentioned that the site looks good in Lynx, the text-based browser, but still asked about a shell script to parse it. I thought a shell script would be overkill: why not a simple alias that searches the site in Lynx?

Giving it a try, the obstacle is that aliases always include the space between the alias and its parameters. As usual, Stack Exchange provided the right direction. With some tweaking, I was able to add this alias to ~/.bashrc:

alias hints='tmp_f(){ URL_PARAM=$(echo "$@" | sed "s/ /-/g"); lynx -accept_all_cookies https://devhints.io/"$URL_PARAM"; unset -f tmp_f; }; tmp_f'

After reloading the file with source ~/.bashrc , you can simply type hints vim to search for vim on Devhints in Lynx (replace vim with any topic, of course). That reminded me of the Quick Search feature in Firefox, so I decided to create a few more aliases to mirror what I use in Firefox and see how well the same sites work as pseudo command line tools:

alias abbr='tmp_f(){ URL_PARAM=$(echo "$@" | sed "s/ /+/g"); lynx -accept_all_cookies https://www.acronymfinder.com/"$URL_PARAM".html; unset -f tmp_f; }; tmp_f' alias dict='tmp_f(){ URL_PARAM=$(echo "$@" | sed "s/ /+/g"); lynx -accept_all_cookies http://www.dictionary.com/browse/"$URL_PARAM"; unset -f tmp_f; }; tmp_f' alias ddg='tmp_f(){ URL_PARAM=$(echo "$@" | sed "s/ /+/g"); lynx -accept_all_cookies https://duckduckgo.com/lite/?q="$URL_PARAM"; unset -f tmp_f; }; tmp_f' alias duck='ddg' alias ports='tmp_f(){ URL_PARAM=$(echo "$@" | sed "s/ /+/g"); lynx -accept_all_cookies https://www.freshports.org/search.php?query="$URL_PARAM"; unset -f tmp_f; }; tmp_f' alias wiki='tmp_f(){ URL_PARAM=$(echo "$@" | sed "s/ /+/g"); lynx -accept_all_cookies https://en.wikipedia.org/w/index.php?search="$URL_PARAM"; unset -f tmp_f; }; tmp_f'

It's no surprise that these sites all look good in Lynx. Now the question is how often I'll remember to use these new aliases.