You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
527 B
Bash

#!/usr/bin/env bash
toduck() {
local in=/dev/stdin
local out=/dev/stdout
local file="$1"
if [[ -n $file ]];then
in="$file"
out="$(mktemp)"
fi
duck="https://lite.duckduckgo.com/lite?kd=-1&kp=-1&q=" # 🦆
while IFS= read -r line; do
if [[ $line =~ \[([^\]]+)\]\(\) ]]; then
text="${BASH_REMATCH[1]}"
line=${line/\[*\]\(\)/[$text]($duck$(urlencode "$text"))}
fi
echo "$line" >> $out
done < "$in"
if [[ -n $file ]]; then
cp "$out" "$file"
rm "$out"
fi
}
toduck "$@"