Skip to content

Instantly share code, notes, and snippets.

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