Created
April 1, 2021 06:57
-
-
Save darshitpp/1b5e1ff63934aeeb170b4e215c147507 to your computer and use it in GitHub Desktop.
URL Encode/Decode from Bash/ZSH using Python 2.7 and Python 3
This file contains 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
# Add the following in your ~/.bashrc or ~/.zshrc | |
# No need to visit urlencoder.org or urldecoder.org!! | |
# Python 2.7 | |
# >url_encode 'Hello, this is me' | |
# >===== | |
# Hello%2C%20this%20is%20me | |
url_encode() { | |
python -c "import urllib; print '=====\n' + urllib.quote_plus('$1')" | |
} | |
# >url_encode 'Hello%2C%20this%20is%20me' | |
# >===== | |
# Hello, this is me | |
url_decode() { | |
python -c "import urllib; print '=====\n' + urllib.unquote_plus('$1')" | |
} | |
# Python 3, courtesy https://twitter.com/arion_miles | |
# >url_encode 'Hello, this is me' | |
# >===== | |
# Hello%2C%20this%20is%20me | |
url_encode() { | |
python3 -c "from urllib.parse import quote_plus; print('='*5, quote_plus('$1'), sep='\n')" | |
} | |
# >url_encode 'Hello%2C%20this%20is%20me' | |
# >===== | |
# Hello, this is me | |
url_decode() { | |
python3 -c "from urllib.parse import unquote_plus; print('='*5, unquote_plus('$1'), sep='\n')" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment