From 216d1d5ec94cb2dce12d131e1a50e24dda41bb33 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Tue, 25 Apr 2017 02:35:22 -0400 Subject: [PATCH] Add bin/duckduckgo & ddg alias --- bin/duckduckgo | 16 ++++++++++++++++ shell/zsh/aliases.zsh | 2 ++ 2 files changed, 18 insertions(+) create mode 100755 bin/duckduckgo diff --git a/bin/duckduckgo b/bin/duckduckgo new file mode 100755 index 00000000..9da45945 --- /dev/null +++ b/bin/duckduckgo @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +urlencode() { + local LANG=C + for ((i=0;i<${#1};i++)); do + if [[ ${1:$i:1} =~ ^[a-zA-Z0-9\.\~\_\-]$ ]]; then + printf "${1:$i:1}" + else + printf '%%%02X' "'${1:$i:1}" + fi + done +} + +query=$(urlencode "$*") +echo "Opening https://duckduckgo.com/?q=$query" +open "https://duckduckgo.com/?q=$query" diff --git a/shell/zsh/aliases.zsh b/shell/zsh/aliases.zsh index ab56e642..d0cbfc46 100644 --- a/shell/zsh/aliases.zsh +++ b/shell/zsh/aliases.zsh @@ -6,6 +6,8 @@ autoload -U zmv zman() { PAGER="less -g -s '+/^ "$1"'" man zshall; } alias ag='noglob ag' +alias ddg='duckduckgo' + # Canonical hex dump; some systems have this symlinked is-callable hd || alias hd="hexdump -C"