Created
November 26, 2022 10:35
-
-
Save Esonhugh/ffa4249a00880fda95b286c5279b7bd0 to your computer and use it in GitHub Desktop.
shell function of url encode decode
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
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