mirror of
https://github.com/rwxrob/dot
synced 2024-11-18 15:25:52 +00:00
32 lines
621 B
Plaintext
32 lines
621 B
Plaintext
|
#!/usr/bin/env bash
|
||
|
|
||
|
# yeah, i totally stole this from stack exchange, no shame
|
||
|
|
||
|
rawurlencode() {
|
||
|
local string="${1}"
|
||
|
local strlen=${#string}
|
||
|
local encoded=""
|
||
|
local pos c o
|
||
|
|
||
|
for ((pos = 0; pos < strlen; pos++)); do
|
||
|
c=${string:$pos:1}
|
||
|
case "$c" in
|
||
|
[-_.~a-zA-Z0-9]) o="${c}" ;;
|
||
|
*) printf -v o '%%%02x' "'$c'" ;;
|
||
|
esac
|
||
|
encoded+="${o}"
|
||
|
done
|
||
|
echo "${encoded}" # You can either set a return variable (FASTER)
|
||
|
REPLY="${encoded}" #+or echo the result (EASIER)... or both... :p
|
||
|
}
|
||
|
|
||
|
if test -n "$1"; then
|
||
|
rawurlencode "$*"
|
||
|
exit
|
||
|
fi
|
||
|
|
||
|
IFS=
|
||
|
while read -r line; do
|
||
|
rawurlencode "$line"
|
||
|
done
|