dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles
Log | Files | Refs | README | LICENSE Back to index

commit a4bad85c0b4441c2d99cab9d361ff97e25a7bd79
parent 71270b9e34bd95c9fce4e47e8d0df0bf6f1f21a2
Author: Anders Damsgaard <andersd@riseup.net>
Date:   Mon,  2 Oct 2017 06:13:22 -0700

add surfraw integration with duckduckgo's hidden service and add zsh functions

Diffstat:
Mlinks/.config/surfraw/conf | 2+-
Alinks/.config/surfraw/elvi/ddg | 82+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mlinks/.zshrc | 11++++++++++-
3 files changed, 93 insertions(+), 2 deletions(-)

diff --git a/links/.config/surfraw/conf b/links/.config/surfraw/conf @@ -1,3 +1,3 @@ -SURFRAW_text_browser=w3m +SURFRAW_text_browser="w3m" SURFRAW_graphical=no SURFRAW_graphical_browser=open diff --git a/links/.config/surfraw/elvi/ddg b/links/.config/surfraw/elvi/ddg @@ -0,0 +1,82 @@ +#!/bin/sh +# elvis: duckduckgo -- Search the web using duckduckgo hidden service via tor +# andersd@riseup.net 20170929 +# relevant: https://duckduckgo.com/params.html +# similar to duckduckgo elvi, adds more options and defaults to SSL. +. surfraw || exit 1 + +w3_config_hook () { + def SURFRAW_duckduckgo_results "$SURFRAW_results" + def SURFRAW_duckduckgo_base_url "3g2upl4pq6kufc4m.onion" + def SURFRAW_duckduckgo_search search + def SURFRAW_duckduckgo_params "&kg=g" + defyn SURFRAW_duckduckgo_https_arg 1 + defyn SURFRAW_duckduckgo_safe_arg 0 + defyn SURFRAW_duckduckgo_redirect_arg 0 + defyn SURFRAW_duckduckgo_use_javascript 0 + defyn SURFRAW_duckduckgo_got_a_ducky_feeling 0 +} + +w3_usage_hook () { + cat <<EOF +Usage: $w3_argv0 [options] [search words]... +Description: + Surfraw search the web using DuckDuckGo (www.duckduckgo.com) +Local options: + -d,-ducky,-l,-lucky use in case of overwhelming feeling of duckiness + -j,-javascript use javascript + -safe enable safe search + -r,-redirect use redirection + -s,-insecure disable SSL search +EOF + w3_global_usage +} + +w3_parse_option_hook () { + opt="$1" + optarg="$2" + case "$opt" in + -d*|-l|-lu*) setoptyn SURFRAW_duckduckgo_got_a_ducky_feeling 1 ;; + -j|-javascript*) setoptyn SURFRAW_duckduckgo_use_javascript 1 ;; + -safe*) setoptyn SURFRAW_duckduckgo_safe_arg 1 ;; + -r|-redirect*) setoptyn SURFRAW_duckduckgo_redirect_arg 1 ;; + -s|-sec*) setoptyn SURFRAW_duckduckgo_https_arg 0 ;; + *) return 1 ;; + esac + return 0 +} + +w3_config +w3_parse_args "$@" +# w3_args now contains a list of arguments + +if [ "${SURFRAW_duckduckgo_https_arg}" = 0 ] ; then + SURFRAW_duckduckgo_base_url="https://${SURFRAW_duckduckgo_base_url}" +else + SURFRAW_duckduckgo_base_url="http://${SURFRAW_duckduckgo_base_url}" +fi + +# need to send the user to the non-javascript version if using a non-graphical +# browser +if [ "$SURFRAW_duckduckgo_use_javascript" = 0 ]; then + SURFRAW_duckduckgo_base_url="${SURFRAW_duckduckgo_base_url}/lite" +fi + +if [ "$SURFRAW_duckduckgo_safe_arg" = 1 ]; then + SURFRAW_duckduckgo_params="${SURFRAW_duckduckgo_params}&kp=1" +fi + +if [ "$SURFRAW_duckduckgo_redirect_arg" = 1 ] ; then + SURFRAW_duckduckgo_params="${SURFRAW_duckduckgo_params}&kd=1" +fi + +if [ "$SURFRAW_graphical" != "yes" ] ; then + SURFRAW_duckduckgo_params="${SURFRAW_duckduckgo_params}&kf=-1&kz=-1&kq=-1&kv=-1" +fi + +escaped_args=`w3_url_of_arg $w3_args` +if [ "$SURFRAW_duckduckgo_got_a_ducky_feeling" = 1 ]; then + escaped_args="! ${escaped_args}" +fi + +w3_browse_url "${SURFRAW_duckduckgo_base_url}/?q=${escaped_args}${SURFRAW_duckduckgo_params}" diff --git a/links/.zshrc b/links/.zshrc @@ -62,7 +62,16 @@ function cgrep() { egrep --color -i "$@|$"; } function fname() { find . -iname "*$@*"; } function sayfile() { festival --tts $@; } function tnew { tmux new-session -As `basename $PWD` } -function w3mtor { torify w3m http://3g2upl4pq6kufc4m.onion/ } +function w3mtor { + local url + if [ $# -eq 0 ]; then + url="https://check.torproject.org/" + else + url=$1 + fi + torify w3m $url +} +function w3mddg { torify surfraw ddg $@ } #function weather { curl wttr.in/SanDiego; } function weather { curl 'wttr.in/?m'; }