Skip to content

Instantly share code, notes, and snippets.

@b0o
Created July 11, 2018 07:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save b0o/41ff38f4b083fd9f0353824d0df5b485 to your computer and use it in GitHub Desktop.
Save b0o/41ff38f4b083fd9f0353824d0df5b485 to your computer and use it in GitHub Desktop.
rawurlencode() {
local string="$@"
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}"
}
h() {
local u="$(rawurlencode "$@")"
unbuffer curl "https://cheat.sh/$u" | less
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment