Last active
July 13, 2022 03:21
-
-
Save Esonhugh/7093d4d0d68853ccdaa4e158771a0f04 to your computer and use it in GitHub Desktop.
Command line URLEncode URLDecode Func
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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