Skip to content

Instantly share code, notes, and snippets.

@cbrunnkvist
Last active November 12, 2019 07:24
Show Gist options
  • Save cbrunnkvist/7a5e780988cbbef8d28408dc2e730be0 to your computer and use it in GitHub Desktop.
Save cbrunnkvist/7a5e780988cbbef8d28408dc2e730be0 to your computer and use it in GitHub Desktop.
echo $annoyingPath | encodeURI
# I actually just pasted this inline as part of a TC buildstep but hey, wanna get the Gist to color coding correctly
encodeURI() {
# for each char from stdin
old_lc_collate=$LC_COLLATE
LC_COLLATE=C
for c in $(grep -o .)
do
case $c in
[a-zA-Z0-9.~_-/?=&]) printf "$c" ;;
*) printf '%%%02X' "'$c" ;;
esac
done
LC_COLLATE=$old_lc_collate
echo
}
encodeURI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment