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"