Skip to content

Instantly share code, notes, and snippets.

@Esonhugh
Last active July 13, 2022 03:21
Show Gist options
  • Save Esonhugh/7093d4d0d68853ccdaa4e158771a0f04 to your computer and use it in GitHub Desktop.
Save Esonhugh/7093d4d0d68853ccdaa4e158771a0f04 to your computer and use it in GitHub Desktop.
Command line URLEncode URLDecode Func
# Author: Esonhugh
# Date: 2022-07-13
# Usage:
# echo "<yourdata>"| url -e
# echo "<yourdata>"| url --encode
# echo "<yourdata>"| url e
# echo "<yourdata>"| url encode
# url -e "<yourdata>"
# url --encode "<yourdata>"
# url e "<yourdata>"
# url encode "<yourdata>"
# decode as same.
url () {
case "$1" in
(decode | d | -d | --decode) if [ -z "$2" ]
then
\python3 -c "import sys; from urllib.parse import unquote; print(unquote(sys.stdin.read()));"
else
\python3 -c "import sys; from urllib.parse import unquote; print(unquote(' '.join(sys.argv[2:])));" "$@"
fi ;;
(encode | e | -e | --encode) if [ -z "$2" ]
then
\python3 -c "import sys; from urllib.parse import quote; print(quote(sys.stdin.read()[:-1]));"
else
\python3 -c "import sys; from urllib.parse import quote; print(quote(' '.join(sys.argv[2:])));" "$@"
fi ;;
esac
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment