diff options
author | EuAndreh <eu@euandre.org> | 2024-11-14 00:21:09 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2024-11-14 00:21:09 -0300 |
commit | f2a9bee4af2a9cfc8865df91edbbcd5fe69ac36f (patch) | |
tree | dc3905470a30405c78a61286002664bdc62919ed /bin/htmlesc | |
parent | bin/forever: Add "-n" option, remove long options (diff) | |
download | dotfiles-f2a9bee4af2a9cfc8865df91edbbcd5fe69ac36f.tar.gz dotfiles-f2a9bee4af2a9cfc8865df91edbbcd5fe69ac36f.tar.xz |
Move bin/{htmlesc,shesc,uri} to eut
Diffstat (limited to 'bin/htmlesc')
-rwxr-xr-x | bin/htmlesc | 118 |
1 files changed, 0 insertions, 118 deletions
diff --git a/bin/htmlesc b/bin/htmlesc deleted file mode 100755 index 5f3694f..0000000 --- a/bin/htmlesc +++ /dev/null @@ -1,118 +0,0 @@ -#!/bin/sh -set -eu - - -usage() { - cat <<-'EOF' - Usage: - htmlesc [-e|d] [CONTENT...] - htmlesc -h - EOF -} - -help() { - cat <<-'EOF' - - - Options: - -e escape the string (the default action) - -d unescape (de-escape?) the string - -h, --help show this message - - CONTENT a literal string to be escaped - - - Convert data to/from HTML escaping. If CONTENT is not given, - get data from STDIN. - - - Examples: - - Escape HTML control characters in a string: - - $ htmlesc 'a > 5 && !b' - a > 5 && !b - - - Unescape the content from a file: - - $ htmlesc -d < file.html - EOF -} - - -for flag in "$@"; do - case "$flag" in - (--) - break - ;; - (--help) - usage - help - exit - ;; - (*) - ;; - esac -done - -ENCODE=false -DECODE=false -while getopts 'edh' flag; do - case "$flag" in - (e) - ENCODE=true - ;; - (d) - DECODE=true - ;; - (h) - usage - help - exit - ;; - (*) - usage >&2 - exit 2 - ;; - esac -done -shift $((OPTIND - 1)) - -if [ "$ENCODE" = true ] && [ "$DECODE" = true ]; then - printf 'Both -e and -d given. Pick one.\n' >&2 - usage >&2 - exit 2 -fi - -decode() { - sed \ - -e 's|&|\&|g' \ - -e 's|<|<|g' \ - -e 's|>|>|g' \ - -e 's|"|"|g' \ - -e "s|'|'|g" -} - -encode() { - sed \ - -e 's|&|\&|g' \ - -e 's|<|\<|g' \ - -e 's|>|\>|g' \ - -e 's|"|\"|g' \ - -e "s|'|\'|g" -} - -if [ "$DECODE" = true ]; then - FN=decode -else - FN=encode -fi - -if [ $# = 0 ]; then - "$FN" -else - for s in "$@"; do - printf '%s\n' "$s" | "$FN" - done -fi |