#!/bin/bash # Input filters are useful also for non interactive shells (e.g. from vim), so # expand them unconditionally. shopt -s expand_aliases if command -v php &> /dev/null; then # Encode/decode HTML special characters. alias htmlencode="php -r 'echo htmlspecialchars(file_get_contents(\"php://stdin\"), ENT_COMPAT | ENT_XHTML, \"UTF-8\", false);'" alias htmldecode="php -r 'echo htmlspecialchars_decode(file_get_contents(\"php://stdin\"), ENT_COMPAT | ENT_XHTML);'" fi # Decode URL encoded strings. # From https://stackoverflow.com/questions/6250698/how-to-decode-url-encoded-string-in-shell urldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; } # Probably a more robust one. #alias urldecode='python -c "import sys, urllib as ul; print ul.unquote(sys.stdin.read());"'