You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
##Helper Functions
|
|
|
|
|
|
|
|
urlencodespecial() {
|
|
|
|
# urlencode <string>
|
|
|
|
old_lc_collate=$LC_COLLATE
|
|
|
|
LC_COLLATE=C
|
|
|
|
local length="${#1}"
|
|
|
|
for (( i = 0; i < length; i++ )); do
|
|
|
|
local c="${1:i:1}"
|
|
|
|
case $c in
|
|
|
|
[a-zA-Z0-9.~_-]) printf "$c" ;;
|
|
|
|
*) printf '%%%02X' "'$c" ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
LC_COLLATE=$old_lc_collate
|
|
|
|
}
|
|
|
|
|
|
|
|
string="$1"
|
|
|
|
if [ -z "$string" ]; then
|
|
|
|
string="$(cat - | sed 's/^ //')" # For some reason, vim likes to add a space to the begining
|
|
|
|
fi
|
|
|
|
|
|
|
|
#URL
|
|
|
|
urlencodespecial "$string"
|
|
|
|
|