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