Refactor bin/{duckduckgo,urlencode}
This commit is contained in:
parent
28ed7298a7
commit
d16f0d14af
|
@ -1,16 +1,5 @@
|
|||
#!/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 "$*")
|
||||
query=$(urlencode <<< "$*")
|
||||
echo "Opening https://duckduckgo.com/?q=$query"
|
||||
open "https://duckduckgo.com/?q=$query"
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
#!/usr/bin/env python
|
||||
import os, sys, urllib
|
||||
if os.isatty(file.fileno(sys.stdin)):
|
||||
text = sys.argv[1]
|
||||
import sys
|
||||
try:
|
||||
from urllib.parse import quote_plus
|
||||
except ImportError:
|
||||
from urllib import quote_plus
|
||||
|
||||
if sys.argv[1:]:
|
||||
text = " ".join(sys.argv[1:])
|
||||
else:
|
||||
text = "".join(sys.stdin.readlines())
|
||||
print(urllib.quote_plus(text.strip()))
|
||||
print(quote_plus(text.strip()))
|
||||
|
|
Loading…
Reference in a new issue